Math Function in C


The math.h header defines various mathematical functions and one macro. All the functions available in this library take double as an argument and return double as the result. Let us discuss some important functions one by one.

Methods:

  • abs ( ) : Absolute value of return to the positive value
  • sqrt ( ) : The square root of the argument
  • ceil ( ) : Rounds float value up to an integer value
  • floor ( ) : Rounds float value down to an integer value
  • pow ( ) : Value of the first parameter raised to the second parameter
  • round ( ) : Round provides the integer value that is nearest to the float

Source Code

//Math Function
#include<stdio.h>
#include<math.h>
 
int main()
{
 
    printf("\nSQRT  : %0.2f",sqrt(4));
    printf("\nPOW   : %0.2f",pow(2,3));
    printf("\nabs   : %d",abs(-25));
    printf("\nCEIL  : %f",ceil(3.8));
    printf("\nCEIL  : %f",ceil(3.2));
    printf("\nFLOOR : %f",floor(3.8));
    printf("\nFLOOR : %f",floor(3.2));
    printf("\nROUND : %f",round(3.8));
    printf("\nROUND : %f",round(3.2));
    return 0;
}
 
To download raw file Click Here

Output

SQRT  : 2.00
POW   : 8.00
abs   : 25
CEIL  : 4.000000
CEIL  : 4.000000
FLOOR : 3.000000
FLOOR : 3.000000
ROUND : 4.000000
ROUND : 3.000000

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C