floor and ceil

floor and ceil functions comes under math.h header file.
floor is used to round down the value of the decimal number and ceil is used to round up the value of the decimal number.
5656.98
Using floor the value is 5656 and using ceil it is 5657


consider the following c program
#include<stdio.h>
#include<math.h>
#include<conio.h>
{
float a;
clrscr();
printf("Enter any decimal number\n");
scanf("%f",&a);
printf("Using floor the value is %d and using ceil it is %d\n",floor(a),ceil(a));
getch();
}
Output:
Enter any decimal number
In otherwords floor will neglect the decimal part while ceil will add 1 to the mantissa part.Hence we can say that floor is similar to casting.That means floor(a) is equivalent to (int)a or (long)a
These 2 functions do not depend upon the value after decimal point that means if the program is run with the value 5656.01 then the output will be same.
Similarly there is floorl and also ceill which returns long type integers

About This Blog

There is something for everyone. !! A tech blog on various topics. Let it be devops, programming etc; we have it all covered here in layman terms :)

Total Pageviews

Back to TOP