Write a C++ program to input a number from user and check whether given number is even or odd using functions.
#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