You can access a range of math functions for performing various mathematical operations on numbers.
To utilize them, include the math.h header file in your program.
#include <math.h> |
To determine the square root of a number, employ the sqrt() function.
printf(“%f”, sqrt(16)); |
The ceil( ) function rounds a number upward to its nearest integer, while the floor( ) function rounds a number downward to its nearest integer, and both return the result.
printf(“%f”, ceil(1.4)); printf(“%f”, floor(1.4)); |
The pow() function yields the result of raising x to the power of y (xy).
printf(“%f”, pow(4, 3)); |
Below is a table listing other commonly used math functions available in the <math.h> library:
Function |
Description |
abs(x) |
Retrieves the absolute value of x |
acos(x) |
Retrieves the arccosine of x |
asin(x) |
Retrieves the arcsine of x |
atan(x) |
Retrieves the arctangent of x |
cbrt(x) |
Retrieves the cube root of x |
cos(x) |
Retrieves the cosine of x |
exp(x) |
Retrieves the value of Ex |
sin(x) |
Retrieves the sine of x (x is in radians) |
tan(x) |
Retrieves the tangent of an angle |