# C - If Else

## If Statement:

The If statement is used to execute a block of code when condition is true.

### Syntax

if(condition){
statements;
}


### Flow Diagram:

#include <stdio.h>

int main (){
int i = 15;
if ( i % 3 == 0){
printf("%i is divisible by 3.", i);
}
return 0;
}


Output

15 is divisible by 3.


## If-else Statement:

The else statement is always used with If statement. It is used to execute block of codes whenever If condition gives false result.

### Syntax

if(condition){
statements;
}
else{
statements;
}


### Flow Diagram:

#include <stdio.h>

int main (){
int i = 16;
if ( i % 3 == 0){
printf("%i is divisible by 3.\n", i);
}
else{
printf("%i is not divisible by 3.\n", i);
}
return 0;
}


Output

16 is not divisible by 3.


## else if Statement:

else if statement is used to tackle multiple conditions at a time. For adding more conditions, else if statement in used. Please see the syntax.

### Syntax

if(condition){
statements;
}
else if(condition){
statements;
}
...
...
...
else {
statements;
}
}


### Flow Diagram:

#include <stdio.h>

int main (){
int i = 16;
if ( i > 25){
printf("%i is greater than 25.\n", i);
}
else if(i <=25 && i >=10){
printf("%i lies between 10 and 25.\n", i);
}
else{
printf("%i is less than 10.\n", i);
}
return 0;
}


Output

16 lies between 10 and 25.