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?
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.
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".
#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".
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?
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?
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?
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?
Ajay said:
1 decade ago
The Explanation which you people were given was very good. But some people are saying one thing i.e., ceil (1.2) gives 1, and some are saying 2, may I please know the correct answer?
I am confused!
I am confused!
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?
Yogesh said:
1 decade ago
Here you are saying that for >. 5 then only the value will round to next highest integer but if we give as ceil (2.1) also we get ans as 3 then how?
Rambabu said:
1 decade ago
Friends ceil(1.00000001)==>2.0 and floor(1.99999999)==>1.0
And there are no functions like roundup and roundto.
I think it help's to you.
And there are no functions like roundup and roundto.
I think it help's to you.
Hameed said:
9 years ago
To round off 1.66 to 2.0.
#include<stdio.h>
#include<math.h>
int main()
{
printf("Result: %4.1f",ceil(1.66));
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
printf("Result: %4.1f",ceil(1.66));
return 0;
}
Manikandan said:
1 decade ago
What is the difference b/w ceil & floor, and also explain the work of roundup and roundto ?
What is the use of ceil() and floor() function?
What is the use of ceil() and floor() function?
Vineettyagi said:
1 decade ago
ceil()-This function works as follows: if the value is greater than or equal to (_.5) then, it round off a value into the next integer value
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers