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.

Bhavya said:   1 decade ago
ceil(d):double, return a value rounded up to the next higher integer.
floor(d):double,return a value rounded down to the next lower integer.

Suresh said:   1 decade ago
There is a function as round() which gives the rusult as 4 if round(x), x ranges from 3.5 to 3.99 and it is 3 if x ranges from 3.01 to 3.49

Rakesh said:   1 decade ago
#include<stdio.h>

#include<math.h>
void main()
{
printf("%f\n",ceil(1.69));
printf("%f",floor(1.69));
}

Prateek baranwal said:   10 years ago
I think this function is apply the numeric rule following. Ant this function we are use of manage of memory for managing bit or byte.

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?

Maya said:   1 decade ago
What is the answer if ceil (1.2)?

Does it gives 1 or 2? Please help me I was confused by various explanations over here.

Pavan Shinde said:   7 years ago
@All.

ceil()---> Means up.(for ex: 1.66----> 2.000000).
floor()--->Means Down.(for ex:1.44--->1.000000).
(22)

Manojit said:   1 decade ago
If I have this number, 15.4632,
If Round Up to 2 decimal, I get 15.47.
If Round to Nearest 2 decimal, I get 15.46.

Kuldeep said:   1 decade ago
@Maya.

The answer will be 2 because ceil() function only display the next higher integer for the given no.

Vikram said:   1 decade ago
It is good but the people who are doing basics to under stand for them can you explain in deep manner.


Post your comments here:

Your comments will be displayed after verification.