Unit-3 Control Structures

Decision Making Statements In C Language

These statements change the flow of execution depending on a given logical condition. Used to execute or skip some set of instructions based on given condition.

Simple “if” statement :

“if” statement is a powerful decision making statement, and is used to control the flow of execution of statements.

Syntax :

if (Condition or test expression) Statement;

Rest of the program


if (Condition or test expression) { Statement; }

Rest of the program;

It is basically a “Two-way” decision statement (one for TRUE and other for FALSE) It has only one option. The statement as executed only when the condition is true. In case the condition is false the compiler skips the lines within the “if Block”.

The conditional statement should not terminated with Semi-colons (ie 😉 

The Statements following the “if”-statement are normally enclosed in Curly Braces {}. 

The Curly Braces indicates the scope of “if” statement. The default scope is one statement. But it is good practice to use curly braces even with a single statement. The statement block may be a single statement or a group of statements.

If the Test Expression / Conditions are TRUE, the Statement Block will be executed and executes rest of the program.

If the Test Expression / Condition are FALSE, the Statement Block will be skipped and rest of the program executes next.

Flow chart for “if” statement :

Decision Making System

Program: Write a program to check equivalence of two numbers. Use “if” statement.


# include<conio.h>

void main( )

{ int m,n; clrscr( );

printf(“\n Enter two numbers:”); scanf(“%d %d”, &m, &n);


printf(“\n two numbers are equal”); getch(); }

Output :

Enter two numbers: 5 5
Two numbers are equal.

2) “if-else” Statement :

It is observed that the “if” statement executes only when the condition following if is true. It does nothing when the condition is false.

In if-else either True-Block or False – Block will be executed and not both. The “else” Statement cannot be used without “if”.

Syntax :

if ( Test Expression or Condition )


Statements; /*true block

(or) if block */



{ Statements; /* false block (or) else block */


Flow chart :

Decision Making System

Program: Write a program to print the given number is even or odd.

# include<stdio.h> # include<conio.h> main( ) { int n; clrscr( ); printf(“Enter a number:”); scanf(“%d”, &n); if( (n%2)==0 ) printf(“\n The given number is EVEN ”); else printf(“\n The given number is ODD ”); getch( ); }

Output :

Run 1 :
Enter a number : 24
The given number is EVEN
Run 2: /* that means one more time we run the program */
Enter a number : 17
The given number is ODD

(3) Nested “if–else” Statement :

Using of one if-else statement in another if-else statement is called as nested if-else control statement.

When a series of decisions are involved, we may have to use more than one if-else statement in nested form.

Syntax :

if ( Test Condition1) { if ( Test Condition2) { Statement -1; } else { Statement-2; } } else { if ( Test Condition3) { Statement -3;} else { Statement-4; } } /* end of outer if-else *

Program: Program to select and print the largest of the three float numbers using nested “if else” statements.

(4) The “else – if” Ladder :

This is another way of putting if‘s together when multiple decisions are involved. A multipath decision is a chain of if‘s in which the statement associated with each else is an if. Hence it forms a ladder called else–if ladder. 

if else-if, statement is used to execute one code from multiple conditions.


The above construction is known as else if ladders. 

The conditions are evaluated from top to bottom.

As soon as a true condition is found, the statement associated with it is executed and The control is transferred to the Rest of the Program Statement–X (skipping rest of the ladder). When all the “n” conditions become false, then the final else containing the default statement will be executed.

Flow chart :

Decision Making System

Program: Write a program to read three numbers and find the largest one by using “else-if” ladder.

5) The “switch-case” Statement :

Switch is another conditional control statement used to select one option from several options based on given expression value; this is an alternative to the if-else-if ladder.

The switch statement causes a particular group of statements to be chosen from several available groups.

The selection is based upon the current value of an expression which is included with in the switch statement.

The switch statement is a multi-way branch statement. 

In a program if there is a possibility to make a choice from a number of options, this structured selected is useful. The switch statement requires only one argument of int or char data type, which is checked with number of case options.The switch statement evaluates expression and then looks for its value among the case constants.

If the value matches with case constant, then that particular case statement is executed.

If no one case constant not matched then default is executed.

Here switch, case and default are reserved words or keywords. 

Every case statement terminates with colon “:”. 

In switch each case block should end with break statement, i.e.