Question 9
Back to Exercise
What is the output of the following C program?
#include <math.h>
#include <stdio.h>
int main(void) {
printf("%d %d %.1f\n", (int) -3.7, (int) 3.7, floor(-3.7));
return 0;
}
- A -4 3 -4.0
- B -3 3 -4.0 Correct
- C -3 4 -3.0
- D -4 4 -4.0
Correct Answer: Option B
Converting to int truncates toward zero, so −3.7 becomes −3. floor() rounds down, toward −∞, giving −4. They agree only for positive numbers.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!