Answer to Question #336088 in C++ for sami

Question #336088

Receive a number and determine whether it is odd or even.

1
Expert's answer
2022-05-01T19:05:57-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