If value of an angle is input through the keyboard, write a c program to print all its Trigonometric Ratios.
Page Contents
Formula To Convert Degree To Radian
radian = degree * (PI / 180.0);
where PI = 3.14159; (constant value)
Logic to Print all Trigonometric Ratios
First we ask the user to input angle of a Triangle in degrees. Next we convert angel from degrees to radian.
Next we include math.h header file and use methods present in it to get:
sin()
cos()
tan()
To get cosec() = 1 / sin();
To get sec() = 1 / cos();
To get cot() = 1 / tan();
tan() value can also be obtained using sin() / cos();
cot() value can also be obtained using cos() / sin();
Source Code: Print All Trigonometric Ratios: C Program
- #include < stdio.h >
- #include < math.h >
- int main()
- {
- float degree, radian;
- const float PI = 3.14159;
- printf("Enter angle in degree\n");
- scanf("%f", °ree);
- radian = degree * (PI / 180.0);
- printf("Sin(%f) = %f\n", degree, sin(radian));
- printf("Cos(%f) = %f\n", degree, cos(radian));
- printf("Tan(%f) = %f\n", degree, tan(radian));
- printf("Cosec(%f) = %f\n", degree, 1/sin(radian));
- printf("Sec(%f) = %f\n", degree, 1/cos(radian));
- printf("Cot(%f) = %f\n", degree, 1/tan(radian));
- return 0;
- }
Output 1
Enter angle in degree
30
Sin(30.000000) = 0.500000
Cos(30.000000) = 0.866026
Tan(30.000000) = 0.577350
Cosec(30.000000) = 2.000001
Sec(30.000000) = 1.154700
Cot(30.000000) = 1.732052
Output 2
Enter angle in degree
45
Sin(45.000000) = 0.707106
Cos(45.000000) = 0.707107
Tan(45.000000) = 0.999999
Cosec(45.000000) = 1.414214
Sec(45.000000) = 1.414213
Cot(45.000000) = 1.000001
Print All Trigonometric Ratios: C Program
Tan and Cot
- printf("Tan(%f) = %f\n", degree, sin(radian)/cos(radian));
- printf("Cot(%f) = %f\n", degree, cos(radian)/sin(radian));
OR
- printf("Tan(%f) = %f\n", degree, tan(radian));
- printf("Cot(%f) = %f\n", degree, 1/tan(radian));
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert