In: Computer Science
#include<iostream>
using namespace std;
int main(){
int n;
cout<<"Enter a positive number:";
//reading a positive number in range of 1 to 9.
do{
cin>>n;
//checking entered number is within range or not.
if(n>0 && n<=9){
break;
}
else{
cout<<"Please enter valid number(1-9):";
}
}while(1);
//multiplying the number by itself.
n=n*n;
//checking the number is odd.
if(n%2==1){
cout<<n<<" odd"<<endl;
}
//checking the number is even.
else{
cout<<n<<" even"<<endl;
}
return 0;
}
/*Note:- Since 0 is neither positive nor negative this code does
not consider 0 as valid number and hence prompts user to enter
another number.*/