header file in C contains functions for performing common mathematical operations like square root, logarithms, exponents, trigonometric functions, and more. It defines functions such as sqrt(), pow(), ceil(), floor(), sin(), cos(), and tan(). These functions take numeric values as arguments and return the result of applying the mathematical operation. Expressions in C are evaluated based on operator precedence and associativity rules according to the priority of the operators."> header file in C contains functions for performing common mathematical operations like square root, logarithms, exponents, trigonometric functions, and more. It defines functions such as sqrt(), pow(), ceil(), floor(), sin(), cos(), and tan(). These functions take numeric values as arguments and return the result of applying the mathematical operation. Expressions in C are evaluated based on operator precedence and associativity rules according to the priority of the operators.">
C Math
C Math
C Math
C Math Functions
sqrt(4.0) is 2.0
sqrt(x) square root of x sqrt(10.0) is
3.162278
exp(1.0) is 2.718282
exp(x) exponential (ex)
exp(4.0) is 54.598150
log(2.0) is 0.693147
log(x) natural logarithm of x (base e)
log(4.0) is 1.386294
log10(10.0) is 1.0
log10(x) logarithm of x (base 10)
log10(100.0) is 2.0
fabs(2.0) is 2.0
fabs(x) absolute value of x
fabs(-2.0) is 2.0
floor function returns the integer value just lesser floor(9.2) is 9.0
floor(x)
than the given rational value. floor(-9.2) is -10.0
fmod(13.657, 2.333)
fmod(x) remainder of x/y as floating-point number
is 1.992
Function Description Example
Example:
#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%f",fabs(-12));
return 0;
}
Output:
4.000000
4.000000
3.000000
3.000000
4.000000
2.645751
16.000000
27.000000
12.000000
Expressions:
C Expression Evaluation
In the C programming language, an expression is evaluated based on the operator precedence
and associativity. When there are multiple operators in an expression, they are evaluated
according to their precedence and associativity. The operator with higher precedence is
evaluated first and the operator with the least precedence is evaluated last.
10 + 4 * 3 / 2
4 * 3 ====> 12
12 / 2 ===> 6
10 + 6 ===> 16
The expression is evaluated to 16.