Bird
0
0

Consider this code:

hard📝 Application Q9 of 15
C - onditional Statements
Consider this code:
#include <stdio.h>
int main() {
    int score = 75;
    if (score >= 90) {
        printf("Grade A\n");
    } else if (score >= 75) {
        printf("Grade B\n");
    } else {
        printf("Grade C\n");
    }
    return 0;
}

What will be the output and why?
AGrade A, because 75 is greater than 90
BGrade C, because 75 is less than 75
CCompilation error due to else if
DGrade B, because 75 is greater or equal to 75 and less than 90
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the first condition

    score >= 90 is false because 75 is less than 90.
  2. Step 2: Evaluate the else if condition

    score >= 75 is true because 75 equals 75, so this block runs.
  3. Step 3: Confirm else block is skipped

    Since the else if condition is true, the else block is skipped.
  4. Final Answer:

    Grade B, because 75 is greater or equal to 75 and less than 90 -> Option D
  5. Quick Check:

    Conditions checked top-down, first true block runs [OK]
Quick Trick: Check conditions top to bottom, first true runs [OK]
Common Mistakes:
  • Assuming 75 >= 90 is true
  • Thinking else if causes error
  • Ignoring order of conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes