Even Numbers : Any digit or number which can be divided by 2 or groups of 2 are called as even numbers.
Numbers like 0 , 2 , 4 , 6 , 8 , 10 , 12 , 16 ...
Odd Numbers : Numbers other than even numbers are called as odd numbers.
Numbers like 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 ...
Algorithm:
Need to check which numbers are divided by 2 for even odd numbers for a given range indicated by the user.
Read these articles:
Program Code:#include<conio.h>
#include<stdio.h>
int main()
{
int num;
printf("Enter a number\n");
scanf("%d",&num);
printf("\n");
if(num%2==0)
printf(" %d is an Even number",num);
else
printf(" %d is an Odd number",num);
getch();
}
Output: After compile and run , the output will be
Hope that you will find this helpful.
Nice coding. And as a friendly suggestion, you can add 'zero' as an "Undefined Exception" as this code clearly categorize it as "even" ;)
ReplyDeleteHere is a c program to check odd and even numbers using switch case and check odd and even numbers using conditional operator.
ReplyDelete