Object

Write a program that reads an integer and determines whether the integer is even or odd.

Algorithm

  1. Declare integer variable a.
  2. Read a.
  3. IF (a mode 2 = 0), then
    • Write “The number is even”.
    •  ELSE
      • Write “The number is odd”.
    • [End of IF-ELSE structure.]
  4. 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

Design a site like this with WordPress.com
Get started