Answer: Following trigonometric functions are defined in ‘math.h’ header.
double sin(double angle); double cos(double angle); double tan(double angle); double asin(double angle); double acos(double angle); double atan(double angle); double atan2(double x, double y);
Recall that PI radians equals 180 degrees. Functions ‘sin()’, ‘cos()’ and ‘tan()’ take angles, in radians, as arguments and return their sine, cosine and tangent respectively. Functions ‘asin()’, ‘acos()’ and ‘atan()’ return their arc sine, arc cosine and arc tangent respectively. Remember that domain error occurs when arguments to ‘asin()’ or ‘acos()’ isn’t in the range -1 to 1. ‘asin()’ and ‘atan()’ returns a value in the range -PI/2 to PI/2 radians, and ‘acos()’ returns value in range 0 to PI radians.
‘atan2()’ function returns arc tangent of expression x/y but uses the signs of both arguments to determine which quadrant the result lies within. It returns a result in range -PI to PI radians.
Let’s consider a simple C program to learn using ‘sin()’ function,
/* fp_sin_func.c -- trigonometric function 'sin()' returns double */ /* value for angle */ #include <stdio.h> #include <stdlib.h> #include <math.h> /* trigonometric functions defined */ int main(void) { double angle, sine; printf("User, write in angle, in radians, whose sine to be " "computed...\n"); scanf("%lf", &angle); /* calling sin() to compute sine of angle argument */ sine = sin(angle); printf("angle: %lf ,in radians, converted to: %lf sine\n", angle, sine); return 0; }
Notice output, for several arbitrary values, below
User, write in angle, in radians, whose sine to be computed... 4.5 angle: 4.500000 ,in radians, converted to: -0.977530 sine User, write in angle, in radians, whose sine to be computed... 5.0 angle: 5.000000 ,in radians, converted to: -0.958924 sine User, write in angle, in radians, whose sine to be computed... 4.0 angle: 4.000000 ,in radians, converted to: -0.756802 sine User, write in angle, in radians, whose sine to be computed... 1000000000000000000000 angle: 1000000000000000000000.000000 ,in radians, converted to: -0.667120 sine
Sanfoundry Global Education & Learning Series – 1000 C Tutorials.
- Apply for C Internship
- Apply for Computer Science Internship
- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Check C Books