Syntax of Simple if-else
-------------------------
Program:
-------------------------
if(condition)
{
statement1;
statement2;
.
.
.
statement n;
}
else
{
statement1;
statement2;
.
.
.
statement n;
}
Program:
#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.
No comments:
Post a Comment
Thanks for your comments.
-Sameer