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.
Abdulrahman said:
9 years ago
There is not standard function for rounding in c called roundup().
Sirisha said:
9 years ago
What is the difference between roundup() & ceil()?
Xyz said:
9 years ago
When we use roundup() and ceil() functions?
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;
}
Stanly said:
9 years ago
@Raj.
You should use to print the float value by %f instead of %d.
You should use to print the float value by %f instead of %d.
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.
RAJ said:
10 years ago
Why the output is 0 instead of having integer value 2?
#include<stdio.h>
#include<math.h>
int main()
{
printf("\n Result : %d" , ceil(1.44) );
printf("\n Result : %d" , ceil(1.66) );
printf("\n Result : %d" , floor(1.44) );
printf("\n Result : %d" , floor(1.66) );
return 0;
#include<stdio.h>
#include<math.h>
int main()
{
printf("\n Result : %d" , ceil(1.44) );
printf("\n Result : %d" , ceil(1.66) );
printf("\n Result : %d" , floor(1.44) );
printf("\n Result : %d" , floor(1.66) );
return 0;
Anil Chauhan said:
10 years 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);
}
Kmahender said:
1 decade ago
I want to know about different types of functions.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers