C Programming Tutorial
C Programming allows us to perform mathematical operations through the functions defined in
C Math Functions
There are various methods in math.h header file. The commonly used functions of math.h header file are given below.
No. | Function | Description |
---|---|---|
1) | ceil(number) | rounds up the given number. It returns the integer value which is greater than or equal to given number. |
2) | floor(number) | rounds down the given number. It returns the integer value which is less than or equal to given number. |
3) | sqrt(number) | returns the square root of given number. |
4) | pow(base, exponent) | returns the power of given number. |
5) | abs(number) | returns the absolute value of given number. |
C Math Example
Let's see a simple example of math functions found in math.h header file.
#include<stdio.h>
#include <math.h>
int main()
{
printf("\n%f",ceil(5.6));
printf("\n%f",ceil(5.3));
printf("\n%f",floor(5.6));
printf("\n%f",floor(5.2));
printf("\n%f",sqrt(25));
printf("\n%f",sqrt(7));
printf("\n%f",pow(3,3));
printf("\n%f",pow(4,2));
printf("\n%d",abs(-25));
return 0;
}
Output:
6.000000
6.000000
5.000000
5.000000
5.000000
2.645751
27.000000
16.000000
25