0% found this document useful (0 votes)
2 views5 pages

If Else If C Structured-1

Uploaded by

Tribhuvan Dixit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

If Else If C Structured-1

Uploaded by

Tribhuvan Dixit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

If Else If Statement in C

➤ 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) {

// Executes if condition1 is true

} else if (condition2) {

// Executes if condition1 is false and condition2 is true

} else {

// Executes if none of the above conditions are true

}
➤ Flowchart
➤ Example

Explanation to the example above :


It's a simple illustration demonstrating how conditional statements are utilized in real-life
situations like categorization of students by grade.

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

➢ It begins by testing the first condition.

➢ If the first statement returns true, then that block is called and the
others are skipped.

➢ If it returns false, then the next condition is checked. And the


process repeats again.

➢ 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”.

You might also like