C tan() library function

The function double tan(double x); returns the tangent of x, expressed in radians.

Function prototype of tan

double tan(double x);
  • x : A floating point value representing an angle in radians.

Return value of tan

It returns the tangent of x.

C program using tan function

The following program shows the use of tan function to calculate tangent of a radian.

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

#define PI 3.14159265

int main(){
    double value, radian, degree;
    printf("Enter an angle in degree\n");
    scanf("%lf", &degree);
     *  Degree to radian conversion
     *  One degree is equal to PI/180 radians.
     *  Where PI = 22/7 = 3.14159(approx)
    radian = degree * (PI/180.0);
    value = tan(radian);
    printf("The tangent of %lf is %lf\n", degree, value);
    return 0;

Enter an angle in degree
The tangent of 45.000000 is 1.000000
Enter an angle in degree
The tangent of 60.000000 is 1.732051