Preview
if else statement in C language
if else statement contains one condition. If condition evaluates to true, one set of statements will execute. If condition is false other set of statements will execute.
Syntax of if else statement is:
if(Condition-Expression)
{
Statements-1;
}
else
{
Statements-2;
}
Condition-Expression is any conditional expression. If it is true, then Statements-1 will execute otherwise Statements-2 will execute.
Statements-1, Statements-2 are set of valid C Language statements.
Program |
#include<stdio.h> main() { int a; printf(“\nEnter a number:=”); scanf(“%d”,&a); if(a>0) printf(“\nPositive”); else printf(“\nNot positive”); getch(); } |
Output |
Enter a number:= -7 Not positive |
In the above program, a has been entered -7. Condition a>0 is false so printf(“Not positive”) will be executed.