LearnFrenzy
Sign in Take a free test

Decision Making · Predict the Output · Question 4

Marks and attendance rule with an else-if ladder Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

What is the output of the following C program?

main.c
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links