If else Programs in C programming

The if-else statement in C is based on some particular conditions to perform the operations. If and only if the given condition is valid, the operations listed in if block is executed.

If Statement

Depending on the validity of that condition, the if statement is used to test the condition and perform the operations. It is mostly used in the scenario for which there exist different conditions; we need to perform the different operations. The if statement syntax is provided below.

Output:

Program to use multiple if statement to check more than one conditions.

Output:

If-else Statement

The if-else statement is used to achieve two single condition operations. The if-else statement is an extension of the if statement that allows one to perform two different operations, one for the correct condition, and the other for incorrect condition. Here we must remember that if block can’t be executed simultaneously, then otherwise.

Example of simple if-else statement

Output:

Program to check whether a person is eligible to vote or not.

Output:

If else-if ladder Statement

The ladder expression if-else-if is an extension of the state if-else. It is used in a scenario where there are multiple cases for different conditions to be performed. If a condition is true, then the statements specified in the if block will be executed in the if-else-if ladder statement, and if any other condition is true, then the statements specified in the other block will be executed. When the last condition is not valid, the statements specified in the other block are executed. Many other blocks-if possible. It is similar to the switch case statement, where if none of the cases match, the default is executed instead of another row.

The example of an if-else-if statement in C language is given below.

Output:

Program to calculate the grade of the student according to the specified marks.

Output:

One more example

Output:

Pin It on Pinterest

Share This