Control structures:
We control the sequence of the structure of a program is called control structures.
There are three types of control structures
1. Conditional statements:
2. Looping statements
3. Jumping statements
1. Conditional statements: the decision is making based on condition and execute the statements
a. Simple if
b. If…else
c. If….else…if
d. Nested if
e. Switch
a. Simple if: it checks the condition first, if the condition is true then execute block of
statements , otherwise stop the program with out any execution.
Syntax: if(condition)
Statements
false true
conddd
Block of statements
end
#include<stdio.h>
#include<conio.h>
void main()
int num;
clrscr();
printf("enter a number");
scanf("%d",&num);
if(num%2==0)
printf("the given number is even");
getch();
Example :2
#include<stdio.h>
#include<conio.h>
void main()
int age;
clrscr();
printf("enter your age");
scanf("%d",&age);
if(age>18)
{
printf("eligible for vote");
getch();
}
b. If….else: it checks the condition first, if the condition is true then execute block of
statements , otherwise it executes the else block statements
Syntax: if(condition)
Statements
else
statements
false true
conddd
Else Block of
Block of statements
statements
end
#include<stdio.h>
#include<conio.h>
void main()
int num;
clrscr();
printf("enter a number");
scanf("%d",&num);
if(num%2==0)
printf("the given number is even");
else
printf("the given number is odd");
getch();
Example :2
#include<stdio.h>
#include<conio.h>
void main()
int age;
clrscr();
printf("enter your age");
scanf("%d",&age);
if(age>18)
{
printf("eligible for vote");
else
printf("not eligible for vote");
getch();