In this article, you will learn about various types of C programming math library functions with their function prototype.
C standard library provides a huge collection of standard functions for performing various common tasks such as mathematical calculations, input/output, character manipulations, string manipulations etc.
We should use C standard library function when possible instead of writing new functions.
C programming math library functions allow us to perform common mathematical computations. For example:
printf("%.2f", sqrt(16));
The above code will calculate square root of 16 using standard sqrt
library function. For using this function, we should include math.h
header by using preprocessor directive which is shown below:
#include <math.h>
The function arguments can be variables, constant or expressions.
For example: If a=8, b=8
printf("%.2f", sqrt(a + b));
The above statement will calculate and print the square root of a + b
.
[adsense1]
C programming math library functions with description |
---|
sqrt( x ) square root of x |
cbrt( x ) cube root of x (C99 and C11 only) |
exp( x ) exponential function x |
log( x ) natural logarithm of x (base e) |
log10( x ) logarithm of x (base 10) |
fabs( x ) absolute value of x as a floating-point |
ceil( x ) rounds x to the smallest integer not less than x |
floor( x ) rounds x to the largest integer not greater than x |
pow( x, y)x raised to power y (xy) |
fmod( x, y ) remainder of x/y as a floating-point number |
sin( x ) trigonometric sine of x |
cos( x ) trigonometric cosine of x |
tan( x ) trigonometric tangent of x |