Home »
C++ programming language
atan() function with example in C++
C++ atan() function: Here, we are going to learn about the atan() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 28, 2019
C++ atan() function
atan() function is a library function of cmath header, it is used to find the principal value of the arc tangent of the given number, it accepts a number (x) and returns the principal value of the arc tangent of x in radians.
Syntax
Syntax of atan() function:
atan(x);
Parameter(s)
x – is the value whose arc tangent to be calculated.
Return value
double – it returns double type value that is the principal value of the arc tangent of the given number x.
Sample Input and Output
Input:
float x = 0.65;
Function call:
atan(x);
Output:
0.576375
Example
// C++ code to demonstrate the example of
// atan() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
float x;
x = -1.0;
cout<<"atan("<<x<<"): "<<atan(x)<<endl;
x = -0.89;
cout<<"atan("<<x<<"): "<<atan(x)<<endl;
x = 0.65;
cout<<"atan("<<x<<"): "<<atan(x)<<endl;
x = 1;
cout<<"atan("<<x<<"): "<<atan(x)<<endl;
return 0;
}
Output
atan(-1): -0.785398
atan(-0.89): -0.727263
atan(0.65): 0.576375
atan(1): 0.785398
Reference: C++ atan() function