If-Else Statement in C

If-Else Statement in C

This is also one of the most useful conditional statement used in C to check conditions.

Syntax:
if(condition)
{
true statements;
}
else
{
false statements;
}

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

Program :

/* Program to demonstrate if-else statement.
Creation Date : 09 Nov 2010 02:45:12 AM
Author : www.technoexam.com [Technowell Web Solutions, INDIA] */

#include<stdio.h>
#include<conio.h>
int main(void)
{
	int no;
	clrscr();
	printf("\n Enter Number :");
	scanf("%d",&no);
	if(no%2==0)
		printf("\n\n Number is even !");
	else
		printf("\n\n Number is odd !");
	getch();
	return 0;
}

Output :

Enter Number : 11
Number is odd !

Leave A Comment

Your email address will not be published. Required fields are marked *