English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ atan() function usage and example

C++ Library Function <cmath>

C ++the atan() function.

This function returns the arctangent value of a number (parameter) in radians form in<cmath>header file definition.

[Math] tan-1x = atan(x) [C++];

atan() prototype [from C ++ 11Standard Library]

double atan(double x);
float atan(float x);
long double atan(long double x);
double atan(T x); //are of integer type

atan() parameters

The atan() function takes a mandatory parameter (can be positive, negative, or zero)

The return value of atan()

The atan() function returns[-π/ 2, π/ 2]values within the range.

Example1: How does atan() work?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  double x = 57.74, result;
  result = atan(x);
  
  cout << "atan(x) = " << result << " radians " << endl;
  
  //Output Degrees
  cout << "atan(x) = " << result*180/3.1415 << " degrees " << endl;
  
  return 0;
}

When running the program, the output is:

atan(x) = 1.55348 radians
atan(x) = 89.0104 degrees

Example2: atan() function with integer type

#include <iostream>
#include <cmath>
#define PI 3.141592654
using namespace std;
int main()
{
  int x = 14;
  double result;
  
  result = atan(x);
  
  cout << "atan(x) = " << result << " radians " << endl;
  //Output Degrees
  cout << "atan(x) = " << result*180/3.1415 << " degrees " << endl;
  
  return 0;
}

When running the program, the output is:

atan(x) = 1.49949 radians
atan(x) = 85.9169 degrees

  C++ Library Function <cmath>