Computer Science, asked by diribaaboma5, 22 days ago

Write a C++ program that accept a number from the user and determine whether it is odd or even.

Answers

Answered by anindyaadhikari13
1

Solution.

Here comes the approach for the problem.

#include <iostream>

using namespace std;

int main() {

   int n;

   cout<<"Enter a number: ";

   cin>>n;

   if (n%2==0)

       cout<<"Number is even.";

   else

       cout<<"Number is odd.";

   return 0;

}

Explanation.

  • A number is said to be even if it is divisible by 2. Here, we have checked whether the number leaves remainder when divided by 2.
  • If the number leaves any remainder, then the number is odd or else, its even!

See attachment for output.

Attachments:
Similar questions