Easy Tutorial
❮ C Exercise Example82 C Function Mbstowcs ❯

C Library Function - atan2()

C Standard Library - <math.h>

Description

The C library function double atan2(double y, double x) returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant.

Declaration

Here is the declaration for the atan2() function.

double atan2(double y, double x)

Parameters

Return Value

The function returns the arc tangent of y/x in radians, within the range [-pi, +pi].

Example

The following example demonstrates the use of the atan2() function.

#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int main ()
{
   double x, y, ret, val;

   x = -7.0;
   y = 7.0;
   val = 180.0 / PI;

   ret = atan2 (y,x) * val;
   printf("The arc tangent of x = %lf, y = %lf ", x, y);
   printf("is %lf degrees\n", ret);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

The arc tangent of x = -7.000000, y = 7.000000 is 135.000000 degrees

C Standard Library - <math.h>

❮ C Exercise Example82 C Function Mbstowcs ❯