Professional Documents
Culture Documents
IF-ELSE
if(<expression>) if(<expression>)
{ {
<statement block> <statement block 1>
} }
or else
{
<statement block 2>
}
●
C treats logical values as integer data type with value 0 for false and
non-zero for true.
●
Therefore, the <statement block> in the first syntax and <statement
block 1> in the second syntax is executed if <expression> evaluates to
true, i.e. evaluates to a non-zero value.
●
Even a negative value is treated as true.
●
Note that enclosing the block within curly braces becomes mandatory
if the statement block consists of multiple statements.
●
The <statement block 2> is executed when the <expression> in the if
statement evaluates to false, i.e evaluates to a zero value.
Example
#include <stdio.h>
main()
{
int min, x, y;
printf("\nProvide two numbers:");
scanf("%d %d", &x, &y);
fflush(stdin);