Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c
math
communitycreator

What is atan() in C?

harris910

The atan() functionalso called the arc tangent function returns the inverse tangent of a number. To be more specific, it returns the inverse tangent of a number in radians.

Figure 1 shows the mathematical representation of the atan() function and Figure 2 shows the visual representation of the atan() function.

Figure 1: Mathematical representation of inverse tangent function
Figure 2: Visual representation of inverse tangent function

Note: The math.h header file is required for this function.

To convert radians to degrees, use the following formula.

degrees = radians * ( 180.0 / PI )

Syntax

double atan(double num)

Parameter

This function requires a number as a parameter. The parameter must be a double value between -1 and 1.

  • -1 <= parameter <= 1

Return value

atan() returns the inverse tangent of a number (radian double value) that is sent as a parameter. The return value lies in interval [-pi/2,pi/2] radians.

Example

#include<stdio.h>
//header file
#include<math.h>

int main() {
    //positive number in radians
    printf("The arc tangent of %lf is %lf radians \n", 0.5, atan(0.5));

    // negative number in radians
    printf("The arc tangent of %lf is %lf radians \n", -0.5, atan(-0.5));

    //applying atan() and then converting the result in radians to degrees
    // radians = 1.0
    // PI = 3.14159265
    double result=atan(1.0) * (180.0 / 3.14159265);
    printf("The arc tangent of %lf is %lf degrees \n", 1.0, result);


}

RELATED TAGS

c
math
communitycreator
RELATED COURSES

View all Courses

Keep Exploring