C Program to implement Simple if else
Syntax of Simple if-else
——————————
——————————
if(condition)
{
statement1;
statement2;
.
.
.
statement n;
}
else
{
statement1;
statement2;
.
.
.
statement n;
}
{
statement1;
statement2;
.
.
.
statement n;
}
else
{
statement1;
statement2;
.
.
.
statement n;
}
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include<stdio.h> void main() { int num; printf(" >>> c program to implement simple if-else <<< \n\n"); printf("\n Enter the number: "); scanf("%d",&num); if(num%2==0) //% operator returns remainder { printf("\n Entered number is Even Number \n"); } else { printf("\n Entered number is Odd Number \n\n"); } } |
Output:
Explanation:
In the above program, if statements are executed if the condition is true. otherwise else statements are executed. And else statements are executed only if the if condition fails.