- C Programming allows us to perform mathematical operations through the functions defined in <math.h> header file.
- The <math.h> header file contains various methods for performing mathematical operations such as sqrt(), pow(), ceil(), floor() etc.
C MATHS FUNCTIONS
Function | Description | |
---|---|---|
ceil(number) | rounds up the given number. It returns the integer value which is greater than or equal to the given number. | |
floor(number) | rounds down the given number. It returns the integer value which is less than or equal to the given number. | |
sqrt(number) | returns the square root of given number. | |
pow(base, exponent) | returns the power of the given number. | |
abs(number) | returns the absolute value of given number. |
C MATHS EXAMPLES
#include<stdio.h>
#include <math.h>
int main(){
printf("\n%f",ceil(3.6));
printf("\n%f",ceil(3.3));
printf("\n%f",floor(3.6));
printf("\n%f",floor(3.2));
printf("\n%f",sqrt(16));
printf("\n%f",sqrt(7));
printf("\n%f",pow(2,4));
printf("\n%f",pow(3,3));
printf("\n%d",abs(-12));
return 0;
}
OUTPUT
4.000000
4.000000
3.000000
3.000000
4.000000
2.645751
16.000000
27.000000
12