Prev Next
C sin() cos() tan() exp() log() function:
- sin( ), cos( ) and tan( ) functions in C are used to calculate sine, cosine and tangent values.
- sinh( ), cosh( ) and tanh( ) functions are used to calculate hyperbolic sine, cosine and tangent values.
- exp( ) function is used to calculate the exponential “e” to the xth power. log( ) function is used to calculates natural logarithm and log10( ) function is used to calculates base 10 logarithm.
- ”math.h” header file supports all these functions in C language.
Example program for sin(), cos(), tan(), exp() and log() in C:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <stdio.h> #include <math.h> int main() { float i = 0.314; float j = 0.25; float k = 6.25; float sin_value = sin(i); float cos_value = cos(i); float tan_value = tan(i); float sinh_value = sinh(j); float cosh_value = cosh(j); float tanh_value = tanh(j); float log_value = log(k); float log10_value = log10(k); float exp_value = exp(k); printf("The value of sin(%f) : %f \n", i, sin_value); printf("The value of cos(%f) : %f \n", i, cos_value); printf("The value of tan(%f) : %f \n", i, tan_value); printf("The value of sinh(%f) : %f \n", j, sinh_value); printf("The value of cosh(%f) : %f \n", j, cosh_value); printf("The value of tanh(%f) : %f \n", j, tanh_value); printf("The value of log(%f) : %f \n", k, log_value); printf("The value of log10(%f) : %f \n",k,log10_value); printf("The value of exp(%f) : %f \n",k, exp_value); return 0; } |
Output:
The value of sin(0.314000) : 0.308866
The value of cos(0.314000) : 0.951106 The value of sinh(0.250000) : 0.252612 The value of cosh(0.250000) : 1.031413 The value of tanh(0.250000) : 0.244919 The value of log(6.250000) : 1.832582 The value of log10(6.250000) : 0.795880 The value of exp(6.250000) : 518.012817 |
Other inbuilt arithmetic functions in C:
- “math.h” and “stdlib.h” header files support all the arithmetic functions in C language. All the arithmetic functions used in C language are given below.
- Click on each function name below for detail description and example programs.
Function
|
Description
|
abs ( ) | This function returns the absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C. |
floor ( ) | This function returns the nearest integer which is less than or equal to the argument passed to this function. |
round ( ) | This function returns the nearest integer value of the float/double/long double argument passed to this function. If decimal value is from “.1 to .5”, it returns integer value less than the argument. If decimal value is from “.6 to .9”, it returns the integer value greater than the argument. |
ceil ( ) | This function returns nearest integer value which is greater than or equal to the argument passed to this function. |
sin ( ) | This function is used to calculate sine value. |
cos ( ) | This function is used to calculate cosine. |
cosh ( ) | This function is used to calculate hyperbolic cosine. |
exp ( ) | This function is used to calculate the exponential “e” to the xth power. |
tan ( ) | This function is used to calculate tangent. |
tanh ( ) | This function is used to calculate hyperbolic tangent. |
sinh ( ) | This function is used to calculate hyperbolic sine. |
log ( ) | This function is used to calculates natural logarithm. |
log10.(.) | This function is used to calculates base 10 logarithm. |
sqrt ( ) | This function is used to find square root of the argument passed to this function. |
pow ( ) | This is used to find the power of the given number. |
trunc.(.) | This function truncates the decimal value from floating point value and returns integer value. |