If Else If C Structured-1
If Else If C Structured-1
➤ Definition
The "if else if" statement in C is used to execute different blocks of code based on the multiple
conditions. It begins with an "if" statement, followed by one or more "else if" conditions, and
ends with an "else" to handle the case in which none of the statements were true.
This statement is usually used in the places where we need to execute a statement after checking
multiple conditions. This is very similar to the “switch” statement in C but much more efficient
and flexible.
➤ Syntax
if (condition1) {
} else if (condition2) {
} else {
}
➤ Flowchart
➤ Example
This C program allows a user to input a numeric grade (on a scale of 100) and subsequently
calculates the corresponding letter grade using an if-else if-else statement. Based on the
input value, the program checks against pre-specified thresholds—90 and above is assigned
an 'A', 80–89 an 'B', and so on—to scores below 60, which are assigned an 'F'. The design
ensures that a single condition is executed alone, keeping the grading logic tight and
efficient.
➤ Working
➢ If the first statement returns true, then that block is called and the
others are skipped.
➢ If none of the above conditions are fulfilled, the last "else" block (if
used) executes.
➤ QUESTIONS :
5 Marks Questions
Question 1:
Define the if else if in C. Write its syntax and explain with an example how it checks
conditions sequentially and chooses which block to execute.
Question 2:
Write a C program using the if else if statement to classify an entered integer as
positive, negative, or zero. Explain how the program decides which condition to
execute.
10 Marks Questions
Question 1:
What is the purpose of using if else if in C programming? Provide the basic syntax,
explain its logical flow, and relate it to a real-life example such as categorizing
student results or traffic signal decisions.
Question 2:
Using examples from grading systems and number classification, compare how if,
else if, and else blocks are structured and evaluated. Describe at least three real-
world applications where if else if improves decision-making in code logic.
➤ References
➢ Kernighan & Ritchie, The C Programming Language (2nd ed.).
➢ Programiz, “C if.else Statement”.
➢ GeeksforGeeks, “Decision Making in C”.