Object
Write a program that reads an integer and determines whether the integer is even or odd.
Algorithm
- Declare integer variable a.
- Read a.
- IF (a mode 2 = 0), then
- Write “The number is even”.
- ELSE
- Write “The number is odd”.
- [End of IF-ELSE structure.]
- Exit.
Flowchart

C++ Source Code
// program 17
#include<iostream>
using namespace std;
int main()
{
int a;
cout << "Enter any number: ";
cin >> a;
cout << (a % 2 == 0 ? "The number is even" : "The number is odd");
return 0;
}
C Source Code
/*program 17*/
#include<stdio.h>
int main()
{
int a;
printf("Enter any number: ");
scanf("%d", &a);
printf(a%2==0? "The number is even":"The number is odd");
return 0;
}
Output
Enter any number: 27
The number is odd
