Nested if statement is same as if..else statement the nested if is execute inner if condition in the single if statement for execute if into if condition and execute else part in the nesting if condition.
if(true condition)
{
if(true condition)
{
statement;
}
else
{
statement;
}
}
else
{
statement;
}
in this example check username and password using nesting if condition.
#include<stdio.h>
#include<conio.h>
void main()
{
char uname;
char pass;
clrscr();
printf("Enter Your Username:");
scanf("%c",&uname);
printf("Enter Your Password:");
scanf("%c",&pass);
if(uname == 'bharat')
{
if(pass == 'makwana')
{
printf("Welcome Mr. Bharat Makwana");
}
else
{
printf("Sorry Your Password is Incorrect");
}
}
else
{
printf("Sorry Your Username is Incorrect");
}
getch();
}