Thursday, February 17, 2011

Decision Making and Branching

Write a program to determine whether a given number is 'odd' or 'even' and print the message
NUMBER IS EVEN
or
NUMBER IS ODD
(a) without using else option, and (b) with else option.

#include <stdio.h>
void main()
{
int a,b;
printf("Enter an Integer number:");
scanf("%d",&a);
if(a%2==0)
printf("\nNUMBER IS EVEN");
if(a%2!=0)
printf("\nNUMBER IS ODD");
printf("\nEnter one more integer number:");
scanf("%d",&b);
if(b%2==0)
printf("\nNUMBER IS EVEN");
else
printf("\nNUMBER IS ODD");
getch();
}

No comments:

Post a Comment