Receive a number and determine whether it is odd or even.
#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;
}
Comments
Leave a comment