Question 5
Back to Exercise
45 of 60 students passed (75%). What does the program print, and why?
#include <stdio.h>
int main(void) {
int passed = 45, total = 60;
if (passed / total * 100 >= 50)
puts("more than half passed");
else
puts("less than half passed");
return 0;
}
- A more than half passed
- B less than half passed – 45 / 60 is 0 in integer division, so the percentage is 0 Correct
- C It crashes
- D It does not compile
Correct Answer: Option B
Evaluation goes left to right: 45 / 60 truncates to 0 before the multiplication. Multiply first – passed * 100 / total – or compare without dividing: passed * 2 >= total.
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!