**Question:**What are Floor, Ceiling, Absolute Value and Remainder Functions in Standard C Library?

**Answer:** Standard C Library defines ‘floor()’, ‘ceil()’, ‘fabs()’ and ‘fmod()’ functions with return values and their arguments as type ‘double’ because of greater range of double values over ‘integer’ values. These are prototyped as below,

double floor(double value); double ceil(double value); double fabs(double value); double fmod(double val1, double val2);

Notice that ‘floor()’ function returns largest integral value not greater than its argument. ‘ceil()’ function returns smallest integral value not less than its argument. ‘fabs()’ returns absolute value of its argument and fmod() returns remainder of division of val1 by val2. Let’s take examples of ‘floor()’ and ‘ceil()’ functions below

/* fp_floor_fun.c -- 'floor()' returns largest integer not greater */ /* than its argument */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { double value, result; printf("User, enter value for 'floor' evaluation...\n"); scanf("%lf", &value); /* let's evaluate 'floor' of 'value' */ result = floor(value); printf("'floor' of \"%lf\": %lf\n", value, result); return 0; }

User, enter value for 'floor' evaluation... 3.5 'floor' of "3.500000": 3.000000 User, enter value for 'floor' evaluation... -122 'floor' of "-122.000000": -122.000000 User, enter value for 'floor' evaluation... -12.23 'floor' of "-12.230000": -13.000000

/* fp_ceil_fun.c -- 'ceil()' returns smallest integer not less */ /* than its argument */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { double value, result; printf("User, enter value for 'ceiling' evaluation...\n"); scanf("%lf", &value); /* let's evaluate 'ceiling' of 'value' */ result = ceil(value); printf("'ceil' of \"%lf\": %lf\n", value, result); return 0; }

User, enter value for 'ceiling' evaluation... 23.3 'ceil' of "23.300000": 24.000000 User, enter value for 'ceiling' evaluation... -12.453 'ceil' of "-12.453000": -12.000000

Try to work-out other two interesting functions to understand them by implementing.

advertisement

advertisement

**Sanfoundry Global Education & Learning Series – 1000 C Tutorials.**

If you wish to look at all C Tutorials, go to C Tutorials.

**Related Posts:**

- Check Computer Science Books
- Apply for C Internship
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Practice Computer Science MCQs