Mathematical Functions in C
C programming provides a rich set of mathematical functions, primarily found within the <math.h> header file. To utilize these functions, this header file must be included at the beginning of the C source code.
Math Functions
ceil(x) Get smallest integral value that exceeds x.
floor(x) Get largest integral value less than x.
fmod(x,y) Divide x by y with integral quotient and return remainder.
abs(n) Find absolute value of integer n.
fabs(x) Compute absolute value of x.
log(x) Compute log(x).
log10(x) Compute log to the base 10 of x.
exp(x) Compute exponential of x
pow(x, y) Compute x raised to the power y.
sqrt( x) Compute the square root of x.
Trigonometric Functions
sin(x) Compute sine of angle in radians.
cos(x) Compute cosine of angle in radians.
tan( x) Compute tangent of angle in radians.
acos(x) Compute arc cosine of x.
asin(x) Compute arc sine of x.
atan(x) Compute arc tangent of x.
atan2(y,x) Compute arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.
Hyperbolic Functions
sinh(x) Compute the hyperbolic sine of x.
cosh(x) Compute the hyperbolic cosine of x.
tanh( x) Compute the hyperbolic tangent of x.
C Example Program for math functions
#include<stdio.h>
main()
{
printf("\n Maths Functions");
printf("\n ***************");
printf("\nCeil(2.546) = %f",ceil(2.546));
printf("\nFloor(2.546) = %f",floor(2.546));
printf("\nFMod(5.0/2.0) = %f",fmod(5.0,2.0));
printf("\nAbs(-5) = %f",abs(-5));
printf("\nFAbs(-5.0) = %f",fabs(-5.0));
printf("\nLog(1.234) = %f",log(1.234));
printf("\nLog10(1.234) = %f",log10(1.234));
printf("\nExp(1.234) = %f",exp(1.234));
printf("\nPow(5,3) = %f",pow(5,3));
printf("\nSqrt(9) = %f",sqrt(9));
printf("\n Trigonometric Functions");
printf("\n ***********************");
printf("\nSine(90) = %f",sin(90*3.14/180));
printf("\nCosine(90) = %f",cos(90*3.14/180));
printf("\nTangent(90) = %f",tan(45*3.14/180));
printf("\nArc Sine(0.7) = %f",asin(0.7));
printf("\nArc Cosine(0.7) = %f",acos(0.7));
printf("\nArc Tangent(0.7) = %f",atan(0.7));
printf("\nArc Tangent(0.7/2.0) = %f",atan2(0.7,2.0));
printf("\n Hyperbolic Functions");
printf("\n ********************");
printf("\nHyperbolic Sine(0.7) = %f",sinh(0.7));
printf("\nHyperbolic Cosine(0.7) = %f",cosh(0.7));
printf("\nHyperbolic Tangent(0.7) = %f",tanh(0.7));
}
No comments:
Post a Comment