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 6 of 8.

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.

Deepa said:   1 decade ago
Thanks.

Sri said:   1 decade ago
Roundoff means? here why we chose the ceil function only?

Bhavana said:   1 decade ago
Good explanation by sasikumar.

HIMANSHU said:   1 decade ago
Binit and Suresh is quite right!!

Binit said:   1 decade ago
ceil() - roundup a float no to its upper integer value
ex : ceil(1.9) = 2.0000
ceil(1.1) = 2.0000

floor() - roundup a float no to its lower integer value

ex : floor(1.9) = 1.0000
floor(1.1) = 1.0000

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

Suresh said:   1 decade ago
Dear friends, there is no functions like roundup() and roundto().

Krishna said:   1 decade ago
Thanks for eplanation.

What is static and global variable?

Purnima said:   1 decade ago
@sasi.

Here you are saying that for >. 5 then only the valu will round to next higest integer but if we give as ceil (2. 1) also we get ans as 3 then how?

And for roundup value is it >. 5 or may anything?


Post your comments here:

Your comments will be displayed after verification.