C math library function atan()


In this article, you will learn about C math library function atan() that computes arc tangent with explanation and example.

C math library function atan()

atan() is the standard C math library function that is defined in math library math.h.

#include<math.h>

Function prototype of C math library function atan()

double atan( double x );

where,

x = floating point value of any range

Return Value of atan( )

This function returns the arc tangent (inverse tan) in radians of x that ranges in the interval [ -pi / 2, +pi / 2 ].

The return type is double.

Example: Program to demonstrate the use of C math library function atan()

/*Use of math library function atan*/

#include<stdio.h>
#include<math.h>
#define PI 3.1415926

int main()
{
   double x, y;

   x = 0.5;
   y = -1.5;

   //calculation arc tan in radians
   printf("atan(%.2lf) = %.2lf (radians)\n\n", x, atan( x ));

   //calculation arc tan in degrees
   printf("atan(%.2lf) = %.2lf (degree)\n\n", x, atan( x ) * 180 / PI );

   //calculation arc tan in radians
   printf("atan(%.2lf) = %.2lf (radians)\n\n", y, atan( y ));

   //calculation arc tan in degrees
   printf("atan(%.2lf) = %.2lf (degree)\n", y, atan( y ) * 180 / PI );

   return 0;
}

Output

c function atan output

Explanation

In the above program, we have calculated the arc tan of x and y in radian and degree.

We have defined macro PI for representing the value of pi.