Performing Mathematical Operations in C : A Comprehensive Guide


C programming language provides a set of built-in math functions that can be used to perform various mathematical operations, such as:

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

These functions are defined in the #include<math.h> library and are widely used in C programming to perform various mathematical operations. Keep in mind that, some of the math functions may not be supported on all platforms.

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