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:
79 comments Page 3 of 8.

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.

Stanly said:   9 years ago
@Raj.

You should use to print the float value by %f instead of %d.

Aka said:   2 weeks ago
Nice, good. Thanks all for explaining.

Ranjith said:   8 years ago
Yes, correct @Akshatha.

Amulya said:   8 years ago
If ceil() round of to next value if it is greater than or equal to 5 then why is 1.44 is round off to 2.000000 and not 1.000000 it is less than 5, right?

Shivkumar said:   8 years ago
What is difference between ceil() and floor() funtion?

Abdulrahman said:   9 years ago
There is not standard function for rounding in c called roundup().

Sirisha said:   9 years ago
What is the difference between roundup() & ceil()?


Post your comments here:

Your comments will be displayed after verification.