CodesJava

Easy learning with example program codes

C Math Functions


C Math Functions:

Math functions and constants are already defined in the C library, in <math.h> header file, which can be used to perform mathematical calculations.

C provides various math functions including;

abs() function:

This function is used to get an absolute value of a number.

Syntax:

abs ( number )

ceil() function:

This function is used to get a round up value; greater than or equal to given number.

Syntax:

ceil ( number )

floor() function:

This function is used to get a round down value; less than or equal to given number.

Syntax:

floor ( number )

sqrt() function:

This function is used to get the square root of a number.

Syntax:

sqrt ( number )

pow() function:

This function is used to get the value of base raised to the power of exponent.

Syntax:

pow ( base, exponent )

There are numerous other functions defined by C which are used to perform mathematical operations.

Example:

#include<stdio.h>  
#include <math.h>  
 
void main()
{    
printf("\n%f",ceil(56.698));    
printf("\n%f",floor(78.67));    
printf("\n%f",sqrt(2));    
printf("\n%f",pow(6,2));    
printf("\n%d",abs(-897));	 
}

Output

57.000000
78.000000
1.414214
36.000000
897
Posted in C   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki