The tan() function defined in the math.h header file. It helps to return the tangent value of the given radian value.
double tan(double x) #where x can be in int, float or long double
The tan() function takes a single parameter which is a value representing an angle expressed in radians.
Parameter | Description | Required / Optional |
---|---|---|
double value | A double value indicates angle in radians | Required |
The return value of tan() function is a number between 1 and -1.
Input | Return Value |
---|---|
-1<x ≥ 1 | a number greater than or equal to 0 |
x < -1 | NaN (not a number) |
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main () {
double v;
double output;
v = 2.3;
output = tan(v);
printf("The value of tan(%.2lf) = %.2lf\n", v, output);
v = -2.3;
output = tan(v);
printf("The value of tan(%.2lf) = %.2lf\n", v, output);
v = 0;
output = tan(v);
printf("The value of tan(%.2lf) = %.2lf\n", v, output);
return 0;
}
Output:
The value of tan(2.30) = -1.12 The value of tan(-2.30) = 1.12 The value of tan(0.00) = 0.00
#include <stdio.h>
#include <math.h>
int main () {
double A=0.5,B=1;
printf("The tangent value of %f is:%f\n",A,tan(A));
printf("The tangent value of %f is:%f\n",B,tan(B));
return 0;
}
Output:
The tangent value of 0.500000 is: 0.546302 The tangent value of 1.000000 is: 1.557408