C Programming Tutorial
Computer Tutorial

The if-else Statement



The if-else Statement

if expression evaluates to true (anything other than 0), the statement or block that forms the target of if is executed; otherwise, the statement or block that is the target of else will be executed, if it exists. Remember, only the code associated with if or the code associated with else executes, never both.

The general form of if-else statement is :

if ( condition / expression  )
{
Statements to be executed ;
.
.
}
else
{
Statements to be executed ;
.
.
}

C Program to show the use of if-else statement :

\* C Program to show the use of if-else statement *\
# include < stdio.h >
int   main( )
{

int   num  ;
printf(" Enter any number : ") ;
scanf("%d ", & num) ;
if ( num >= 10  )
{

printf("\n Entered number is greater than or equal to 10. ") ;

}
else
{

printf("\n Entered number is less than 10 ") ;

}
return ( 0 );

}