C Math Functions: Performing Mathematical Operations
Explore the wide range of math functions available in C for performing various mathematical tasks, such as square root, power, and trigonometric calculations. These functions require the inclusion of the math.h
header file in your program to access them efficiently and handle complex mathematical operations.
C Math Functions
Math Functions
There is a list of math functions available that allow you to perform mathematical tasks on numbers.
To use them, you must include the math.h
header file in your program:
Syntax
#include
Square Root
To find the square root of a number, use the sqrt()
function:
Syntax
printf("%f", sqrt(16));
Output
4.000000
Round a Number
The ceil()
function rounds a number upwards to its nearest integer, and the floor()
function rounds a number downwards to its nearest integer and returns the result:
Syntax
printf("%f", ceil(1.4));
printf("%f", floor(1.4));
Output
2.000000
1.000000
Power
The pow()
function returns the value of x to the power of y (x^y
):
Syntax
printf("%f", pow(4, 3));
Output
64.000000