Question 4
Back to Exercise
Students with 90 or more should get a distinction. What does the program print for 95 marks, and why?
#include <stdio.h>
int main(void) {
int marks = 95;
if (marks >= 40)
puts("pass");
else if (marks >= 90)
puts("distinction");
else
puts("fail");
return 0;
}
- A distinction
- B pass – every mark ≥ 90 is already ≥ 40, so the first branch wins and the distinction branch is unreachable Correct
- C fail
- D pass and distinction
Correct Answer: Option B
In a ladder only the first true branch runs, so the more specific test must come first: check >= 90 before >= 40.
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!