If else statement in C language is used when a different sequence of instructions is to be executed depending on the logical value (True / False) of the condition evaluated.
It’s form used in conjunction with if and the syntax for If else statement is
If the condition is true, then the sequence of statements (Statements_1_Block) executes; otherwise the Statements_2_Block following the else part of if-else statement will get executed.
In both the cases, the control is then transferred to Statements_3 to follow the sequential execution of the program.
C program to illustrate if else statement
Write a C program to print whether the given number is even or odd
/* Program to print whether the given number is even or odd*/
main ( )
printf(“Enter a number:\n”);
if (x % 2 == 0)
printf(“\nGiven number is even\n”);
printf(“\nGiven number is odd\n”);
Enter a number:
Given number is even
Enter a number
Given number is odd