Nested If statement with simple program

C language also helps you to use an if statement within other if statement. This is refer as Nested If statement. It is a conditional statement which is used when we want to check more than one conditions at a time in a same program. The conditions are executed from top to bottom checking each condition whether it meets the conditional criteria or not. If it found the condition is true( in parent If)  then it executes the block of associated statements (or baby if statements) of true part else it goes to next condition to execute.

Syntax:

if(condition)

{

if(condition)

{

statements;

}

else

{

statements;

}

}

else

{

statements;

}

In above syntax, the condition is checked first. If it is true, then the program control flow goes inside the braces and again checks the next condition. If it is true then it executes the block of statements associated with it else executes else part.

nested_if

Program :

#include <stdio.h>

#include <conio.h>

void main()

{

int num;

clrscr();

printf(“\n Enter Number :”);

scanf(“%d”,&num);

if(num>0)

{

printf(“\n\n Number is greater than 0 “);

}

else

{

if(no==0)

{

printf(“\n\n It is 0 “);

}

else

{

printf(“Number is less than 0 “);

}

}

getch();

}