C PROGRAM TO CHECK WHETHER A NUMBER IS EVEN OR ODD
Numbers perfectly divisible by 2 are known even
numbers and numbers which are not divisible by 2 are called odd numbers.
This program takes an integer from user and checks
whether that number is even or odd and displays the result.
In this program,
user is asked to enter an integer which is stored in variable num. Then, the
remainder is found when that number is divided by 2 and checked whether
remainder is 0 or not. If remainder is 0 then, that number is even otherwise
that number is odd.
This task is performed using if...else statement in C
programming and the result is displayed accordingly.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
void main()
{
int num;
printf("Enter an integer you want to check: ");
scanf("%d",&num);
if((num%2)==0) /*
Checking whether remainder is 0 or not. */
printf("%d is
even.",num);
else
printf("%d is
odd.",num);
getch();
}
OUTPUT 1:
Enter an integer you want
to check: 25
25 is odd
OUTPUT2:
Enter an integer you want
to check: 22
22 is even
No comments:
Post a Comment