Offers
Thanks for visiting www.technoexam.com. Stay connected with us for more latest programming updates...

You are here : Home >> Tutorials >> C

Go
Basic C Tutorial

Contents
What is C ?
History
Structure of C Program
Variables & Keywords
Constants
Data Types
Operators
Operators Precedence
Conditional Statements
if Statement
if else Statement
nested if else
switch case
Looping Statements
While loop
Do While loop
For loop
Break
Continue
Goto
Functions
Passing Value
Returning Value
Passing & Returning
Recursion
Storage Class
Array
Structure
Pointer
Union
Strings
Header File
Programs Library
Projects Library
Learn More+

Contact Us

+91-8806583119

Nested If-Else Statement in C

It is a conditional statement which is used when we want to check more than 1 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 then it executes the block of associated 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.

Program :

// Program to demonstrate nested if-else statement
#include <stdio.h>
#include <conio.h>
int main(void)
{
	int no;
	clrscr();
	printf("\n Enter Number :");
	scanf("%d",&no);
	if(no>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();
	return 0;
}

Output :

Enter Number : 0

It is 0 !_

Download PDF
Published on: 12th Nov 2010, Last Updated on: 18th Dec 2014

Mr. Dinesh Kudache
AUTHOR: Mr. Dinesh Kudache

Mr. Dinesh is the Founder and CEO of technoexam.com. He had 6+ years experience in Application Programming, System Programming, Web Design and Development, Google Expertise. He had written 5000+ various articles on programming. Browse more articles by this author.

Link this post on your Blog/Website :