Question 4
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int marks = 72, attendance = 68;
if (marks >= 40 && attendance >= 75)
puts("pass");
else if (marks >= 40)
puts("detained: attendance");
else
puts("fail");
return 0;
}
- A detained: attendance Correct
- B pass
- C fail
- D pass and detained: attendance
Correct Answer: Option A
The first condition fails because attendance is below 75. The second only needs the marks, which pass, so the student is detained. Only one branch of a ladder runs.
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!