C uses the keyword if to implement the decision control instruction. The general form of if statement looks like this:
if ( this condition is true )
{
Statement No 1
Statement No 1
.
.
Statement No N
}
next_statement;
The if statement by itself will execute a single statement, or a group of statements when the expression following if evaluates to true. It does nothing when the expression evaluates to false.
Note :
Note: As a general rule, we express a condition using C’s ‘relational’ operators. The relational operators allow us to compare two values to see whether they are equal to each other, unequal, or one is greater than the other.
void main( )
{
int num ;
printf ( "Enter a number less than 5 " ) ;
scanf ( "%d", &num ) ;
if ( num <= 5 )
printf ( "Correct!" ) ;
getch();
}
On execution of this program, if you type a number less than or equal to 5, you get a message on the screen through printf( ). If you type some other number the program doesn’t do anything.