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

Preethi said:   1 decade ago
Give the explaination of functions roundof(),roundto()

Amit Wadhe said:   1 decade 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".

Jayasri said:   1 decade 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

Deepika said:   1 decade ago
Thanks to sasi.

Sudha said:   1 decade ago
Thanks jayasri.

Parmar Vishal said:   1 decade ago
Confusion!!! But some time both the function is give the same out put confuse!

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

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

L.sirisha said:   1 decade ago
What is the difference between roundup() and ceil()?
As both are doing the same thing. ex:ceil(10.5) rounds to a next integer value.i.e.11.even roundup() do the same thing.then what is the difference between these two?

Sai prashanthi said:   1 decade ago
Thanks to sasi and jayashri.

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.