if-else Statement in C Language
Whenever the if statement return false then the else block will be executed. The following example explains the concept of if else block. In this form, a set of statements inside the body of If condition will be executed only if the condition evaluates result as true, otherwise, else block will be executed. The syntax for if-else statement is as follows:-
if(condition)
{
Statements ; //when if condition evaluates result as true
}
else
{
Statements ; //when if condition evaluates result as false
}
#include<stdio.h> #include<conio.h> void main() { int no1, no2; printf("Enter Number 1 : "); scanf("%d",&no1); printf("Enter Number 2 : "); scanf("%d",&no2); if(no1<no2) { printf("Number 1 : %d is smaller number",&no1); } else { printf("Number 2 : %d is smaller number",&no2); } getch(); }
Flow Chart of if else Statement
If statement is used to execute a particular area of code if and only if the condition is true otherwise it is used to executed false block.
ADVERTISEMENT