Question 6
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
printf("%d %.2f %.2f\n", 7 / 2 * 2, 7 / 2 * 2.0, 7 / 2.0 * 2);
return 0;
}
- A 6 6.00 7.00 Correct
- B 7 7.00 7.00
- C 6 7.00 7.00
- D 6 6.00 6.00
Correct Answer: Option A
Evaluation is left to right. In the first two, 7 / 2 is integer division (3) before anything else, so the fraction is already lost. Only 7 / 2.0 divides in floating point.
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!