C Programming - Library Functions - Discussion
Discussion Forum : Library Functions - Find Output of Program (Q.No. 2)
2.
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
float i = 2.5;
printf("%f, %d", floor(i), ceil(i));
return 0;
}
Answer: Option
Explanation:
Both ceil() and floor() return the integer found as a double.
floor(2.5) returns the largest integral value(round down) that is not greater than 2.5. So output is 2.000000.
ceil(2.5) returns 3, while converting the double to int it returns '0'.
So, the output is '2.000000, 0'.
Discussion:
18 comments Page 2 of 2.
Swathi said:
1 decade ago
Can anyone please explain me the procedure of double to int conversion ?
Shubham said:
1 decade ago
This is really confusing. Please somebody explain clearly.
Rakhi Sinha said:
5 years ago
GCC compiler is giving some garbage value instead of 0.
Cvam singh said:
1 decade ago
Please specify that it will return from right or left.
PRIYANKA said:
1 decade ago
Please explain the conversion of double to integer.
Anusha said:
1 decade ago
Can anyone please explain how it becomes 0 ?
Abc said:
1 decade ago
Can anyone explain double to int conversion.
Swapnil Kudale said:
8 years ago
@Djv is correct.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers