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:
80 comments Page 3 of 8.
Anil Soni said:
1 decade ago
What is roundup() & why we use?
Sneha said:
1 decade ago
What the difference between roundup() and ceil()?
Cutie said:
1 decade ago
What is the difference between ceil & roundup and floor & roundto?
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.
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.
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!
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.
Does it gives 1 or 2? Please help me I was confused by various explanations over here.
Raj said:
1 decade ago
@Maya the answer will be 2!
Kuldeep said:
1 decade ago
@Maya.
The answer will be 2 because ceil() function only display the next higher integer for the given no.
The answer will be 2 because ceil() function only display the next higher integer for the given no.
Kmahender said:
1 decade ago
I want to know about different types of functions.
Anil Chauhan said:
1 decade ago
#include <stdio.h>
#include <math.h>
int main ()
{
float val1, val2, val3, val4;
val1 = 1.6;
val2 = 1.2;
val3 = 2.8;
val4 = 2.3;
printf ("value1 = %.1lf\n", ceil(val1));
printf ("value2 = %.1lf\n", ceil(val2));
printf ("value3 = %.1lf\n", ceil(val3));
printf ("value4 = %.1lf\n", ceil(val4));
return(0);
}
#include <math.h>
int main ()
{
float val1, val2, val3, val4;
val1 = 1.6;
val2 = 1.2;
val3 = 2.8;
val4 = 2.3;
printf ("value1 = %.1lf\n", ceil(val1));
printf ("value2 = %.1lf\n", ceil(val2));
printf ("value3 = %.1lf\n", ceil(val3));
printf ("value4 = %.1lf\n", ceil(val4));
return(0);
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers