Sometimes we require executing a set of one or more statements based on TRUEness of some condition and another set of one or more statements based on FALSEness of same condition. In such situation we can use if-else statement.
Syntax- of if-else blockif ( condition )
Statements set 1; // one or more statements
Statements set 2; // one or more statements
Here, a condition is specified with if. If the condition is TRUE then statement(s) inside if-block will be executed. If the condition is FALSE, then statement(s) inside else-block will be executed.
#include < stdio.h >
#include < conio.h >
void main ( )
// Variable Declaration
float pa, dis, na;
clrscr ( );
printf ( “ \n Enter the Purchase Amount \n “ );
scanf ( “ %f “, &pa );
if ( pa > = 1000 )
dis = pa * 0.1;
dis = 0 ;
na = pa – dis ;
printf ( “ \n Discount = %f “, dis );
printf ( “ \n Net Amount = %f “, na );
getch ( );
Note- Use of curly brackets (parentheses) in if-block and else-block is not compulsory if there is only one statement inside them.