Math Function Types of math function in C programming with examples


1.It is used to perform the mathematical related operation.

2.There are many predefined math function in C library.
3.All the math functions are predefined in math.h header file.

Math Function
Function nameDescription
sin()It is used to calculate the sine value.
sinh()It is used to calculate hyperbolic sine value.
cos()It is used to calculate the cosine value.
cosh()It is used to calculate hyperbolic cosine value.
tan()It is used to calculate the tangent value.
tanh()It is also used to calculate the hyperbolic tangent value.
sqrt()It is used to calculate square root of value passed to the function.
pow()It is used to calculate the power of a number pow(base,power).
exp()It is used to calculate the exponential of the value passed to the function.
log()It is used to calculate natural logrithm.
log10()It is used to calculate base-10 logrithm.
floor()It always returns minimum round off value.
ceil()It always returns maximum round off value.
round()It returns maximum round off value if the input value is greater than or equal to center value otherwise minimum round off value.
abs()It always returns positive value.
fmod()It is used to convert all the character into lower alphabet.

Example
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float a=2;
printf("sin(2)=%f\n",sin(a));
printf("cos(2)=%f\n",cos(a));
printf("tan(2)=%f\n",tan(a));
printf("exp(2)=%f\n",exp(a));//exponential
printf("log(2)=%f\n",log(a));//natural log
printf("log10(2)=%f\n",log10(a));//log10
printf("sqrt(4)=%f\n",sqrt(4));//square root
printf("cbrt(27)=%f\n",cbrt(27));//cube root
return 0;
}
### Output ###
sin(2)=0.909
cos(2)=-0.416
tan(2)=-2.185
exp(2)=7.389
log(2)=0.693
log10(2)=0.301
sqrt(4)=2
cbrt(27)=3

floor() function
It returns the minimum round off value.
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
printf("%f\n",floor(2.3));
printf("%f\n",floor(2.5));
printf("%f\n",floor(2.8));
return 0;
}
### Output ###
2.0
2.0
2.0

ceil() function
It returns the maximum round off value.
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
printf("%f\n",ceil(2.3));
printf("%f\n",ceil(2.5));
printf("%f\n",ceil(2.8));
return 0;
}
### Output ###
3.0
3.0
3.0


round() function

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
printf("%f\n",round(2.3));
printf("%f\n",round(2.5));
printf("%f\n",round(2.8));
return 0;
}
### Output ###
2.0
3.0
3.0

Here I am requesting if you found this post was helpful for you then let me know by your comment in below comment box and share it with your friend. Also you can contact me on Instagram @rajusunagar_

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thank you!!.......

Post a Comment

0 Comments