Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

10 Nov 2012

C PROGRAM TO IMPLEMENT SIMPLE IF-ELSE IN C

Syntax of Simple if-else
-------------------------
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