The C Programming tan Function is a Math Library Function. It is helpful to calculate the Trigonometry Tangent value for the specified expression. The syntax of the tan is as shown below.
double tan(double number);
Let us see the mathematical formula behind this Trigonometry Tangent function:
Tan(x) = Length of the Opposite Side / Length of the Adjacent Side
TAN Function in C Example
The tan function in the math library allows you to calculate the trigonometric Tangent for the specified values.
This program asks the user to enter his/her own value. Then it will find the tangent value of the user-specified value. Please refer to the ATAN Function and math article to calculate the Arc Tangent of the specified expression.
#include <stdio.h>
#include <math.h>
int main()
{
double tanValue, number;
printf(" Please Enter the Value to Calculate Tangent : ");
scanf("%lf", &number);
tanValue = tan(number);
printf("\n The Tangent, or Tan value of %lf = %f ", number, tanValue);
return 0;
}
TANGENT Function Example 2
This C Programming example allows the user to enter the value in degrees. Next, we are converting the degrees to Radians. And finally, we are finding the Tangent value of the radian
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main()
{
double tanValue, radianVal, degreeVal;
printf(" Please Enter an Angle in degrees : ");
scanf("%lf", °reeVal);
// Convert Degree Value to Radian
radianVal = degreeVal * (PI/180);
tanValue = tan(radianVal);
printf("\n The Tangent, or Tan value of %f = %f ", degreeVal, tanValue);
return 0;
}
Please Enter an Angle in degrees : 60
The Tangent, or Tan value of 60.000000 = 1.732051