Types Of Sequential control structure
- Simple if
- if – else
- else if / if else ladder
- Multiple if / nested if
1.Simple if
In simple if we can check only one condition .
#include<stdio.h>
int main()
{
int age=20;
if(age>=18)
{
printf(“you can apply your driving lisenced.”);
}
return 0;
}
OUTPUT :-
you can apply your driving lisenced.
2.if-else
Here two condition will checked . If the 1st condition will true then statement 1 will be execute , if false then it comes to else statement and statement 2 will be executed .
#include<stdio.h>
int main()
{
int age=20;
if(age>=18)
{
printf(“you are eligible.”);
}
else{
printf(“ERROR”);
}
return 0;
}
OUTPUT:-
you are eligible.
3.else if
If you have multiple condition but we want to execute only then we will use else if .
//take a number and check that number is even odd or zero.
#include<stdio.h>
int main()
{
int num=7;
if(num%2==0){
printf(“even number”);
}
else if(num%2!=0){
printf(“odd number”);
}
else{
printf(“num==0”);
}
return 0;
}
OUTPUT :-
odd number
4.Nested if
if is present inside another if ,then it is called nested if .
//check your user id and password.
#include<stdio.h>
int main()
{
int user_id=123456,password=2002;
if(user_id==123456)
{if(password==2002){
printf(“log in success”);
}
else{
printf(“passwor is incorrect”);
}
}
else{
printf(“user id incorrect”);
}
return 0;
}
OUTPUT:-
log in success