Answer to Question #337930 in C++ for halma

Question #337930

Write a C++ program to input a number from user and check whether given number is even or odd using functions.


1
Expert's answer
2022-05-06T15:36:08-0400
#include <iostream>
using namespace std;
 
int main() {
   int n;
   
   cout<<"Enter integer N: ";
   cin>>n;
   if(!cin){
           cout<<"Invalid input."<<endl;
           cin.clear();
           exit(1);
   }
    
   if(n%2==0)
          cout<<"Even";
    else
        cout<<"Odd";
    cout<<endl;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS