C++ cmath tan-1
时间: 2024-05-07 07:15:27 浏览: 62
The C++ cmath library provides the function atan() which returns the inverse tangent (also known as arctangent) of a given value in radians.
The syntax for using atan() function is:
```
#include <cmath>
double atan(double x);
```
Here, x is the value whose inverse tangent is to be calculated.
Example:
```
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 1.0;
double y = 0.5;
double angle1 = atan(x);
double angle2 = atan(y);
cout << "The inverse tangent of " << x << " is " << angle1 << " radians." << endl;
cout << "The inverse tangent of " << y << " is " << angle2 << " radians." << endl;
return 0;
}
```
Output:
```
The inverse tangent of 1 is 0.785398 radians.
The inverse tangent of 0.5 is 0.463648 radians.
```
Note that the result returned by atan() is in radians. To convert it to degrees, you can use the radian to degree conversion formula: `angle_in_degrees = angle_in_radians * (180 / PI)` where PI is a constant value defined in cmath library.
阅读全文