C++ atan()

C++ atan() returns inverse tangent of a number in radians.

Syntax

The syntax of C++ atan() is

atan(x)

where

ParameterDescription
xA double, float, or long double number.

Returns

The atan() function returns the value in the range of [-π/2, π/2].

The synopsis of atan() function is

double atan(double x);
float atan(float x);
long double atan(long double x);
double atan(T x); // for integral type argument values

Example

In this example, we read x value from the user and find the inverse tangent of this value using atan() function.

C++ Program

#include <iostream>
#include<cmath>
using namespace std;

int main() {
    float x;
    cout << "Enter a value : ";
    cin >> x;
        
    double result = atan(x);
    cout << "atan(" << x << ") : " << result << " radians" << endl;
}

Output

Enter a value : 235
atan(235) : 1.56654 radians
Program ended with exit code: 0
Enter a value : 0
atan(0) : 0 radians
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned the syntax of C++ atan(), and how to use this function to find inverse tangent of a value, with the help of examples.