Write a C++ program that accepts an integer and checks whether it is even or odd and then prints an appropriate message

      

Write a C++ program that accepts an integer and checks whether it is even or odd and then prints an appropriate message.

  

Answers


Martin
// a program to check whether a number is even or odd

#include //header file

using namespace std;

int main()
{
int number; // declare number as integer
cout<<"Enter a number to check whether it is even or odd \n "< cin>>number; //scans the number
if(number%2==0)//condition if the remainder after ? the number with two. If zero, then the number is even
{
cout<<"THE NUMBER IS EVEN \n"< }
else // if not even then it's odd
{
cout<<"THE NUMBER IS ODD \n"<
}


return 0; //return the value to zero. End of program

}
Joshua_white answered the question on March 8, 2018 at 07:54


Next: Describe cultivation of oil palm from land preparation to harvesting
Previous: Write a program that solves a quadratic equation gives the answer for the roots.

View More Computer Science Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions