Nested if statement.
First a condition is checked if it is true then another condition
checked. If it is true another condition is checked. If it also true then a
block of statement is executed. If the first condition is true, then else part
will be executed. we can also check another condition in else part.
Example.
We are going to find big number among three numbers. The program
for it.
#include <stdio.h>
int main()
{
int a,b,c;
printf("enter a:");
scanf("%d",&a);
printf("enter b");
scanf("%d",&b);
printf("enter c");
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("a is big");
}
else
{
printf("c is big");
}
}
else
{
if(b>c)
{
printf("b is big");
}
else
{
printf("c is big");
}
}
return 0;
}
In the above program has been written in c language. It uses
the method of nested if statement. First
a is greater than b is executed if it is true then it check for the second
condition whether the second condition is true or not false. If it also true a
is declared as big number. If the second condition is false then c is declared
as big number .if the first condition is false then it comes to else part. It also checks another condition. If it is
true then b is declared as big number. If it is false then c is declared as big
number.
Will
continue
Muthu
karthikeyan,Madurai.
contact:919629329142
Email:muthu.vaelai@gmail.com.
No comments:
Post a Comment