C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 5)
5.
How would you round off a value from 1.66 to 2.0?
ceil(1.66)
floor(1.66)
roundup(1.66)
roundto(1.66)
Answer: Option
Explanation:
/* Example for ceil() and floor() functions: */

#include<stdio.h>
#include<math.h>

int main()
{
    printf("\n Result : %f" , ceil(1.44) );
    printf("\n Result : %f" , ceil(1.66) );
 
    printf("\n Result : %f" , floor(1.44) );    
    printf("\n Result : %f" , floor(1.66) );

    return 0;
}
// Output:
// Result : 2.000000
// Result : 2.000000
// Result : 1.000000
// Result : 1.000000
Discussion:
80 comments Page 7 of 8.

Deepika said:   2 decades ago
Thanks to sasi.

Jayasri said:   2 decades ago
roundup() function preforms just rounding the value 10.5 to 11
and roundto() function performs like specification if u want to display 2 decimal r three decimal. its like 123.345 u want it for 0 decimal means it displays 123. and for 1 its displays 123.3 like wise it performs

Amit Wadhe said:   2 decades ago
Usage:

#include <math.h>
y = floor( x );

Where:

double x, y;


Description:

"floor" returns the largest integer (represented as a double precision number) that is less than or equal to "x".

Chandan said:   1 decade ago
I take daily life exa.
Ceil mean ceiling fan i.e. Upper limit
Floor mean ground i.e. Lower limit
Here I take upper limit mean +positive infinity n lower is -neg
Infinity

During ceil function we round value toward positive value

i.e. 3.2=4
3.6=4
2.1=3

Anil Soni said:   1 decade ago
What is roundup() & why we use?

Sneha said:   1 decade ago
What the difference between roundup() and ceil()?

Cutie said:   1 decade ago
What is the difference between ceil & roundup and floor & roundto?

Alina said:   1 decade ago
ceil(1.44) = 1.00 and roundup(1.44) = 1.00 so both are same?

Elumalai said:   1 decade ago
Floor : It is used to eliminate the float(decimal)numbers that means if the value is 3.50 means the result is 3.00. It eliminate the .50.

Ceil : It is used to round the next integer value that means if the value is 3.50 or 3.4 the result is 4.

Round : It is used to round up or round down the float numbers based on the numbers. If the value is <3.5 then the result is 3 and >= 3.5 then v will get 4.

Raghu Teja said:   1 decade ago
I understood about ceil and need more clarity about floor().

Can anyone explain me about floor() with an suitable example?


Post your comments here:

Your comments will be displayed after verification.