Answer to Question #49117 in C++ for Salman

Question #49117
Take an integer from user and tell if it is a positive even number, or positive odd, or negative
even or negative odd
1
Expert's answer
2014-11-20T01:25:22-0500
/* Answer on Question #49117- Subject - Programming, C++ */
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int n; // integer
cout << "Enter an integer: ";
cin >> n; //read integer
if ((n > 0) && ( n % 2 )) // check if integer is positive and odd
cout<<"integer is positive odd"<<endl;
else if ((n < 0) && (n % 2)) // check if integer is negative and odd
cout<<"integer is negative odd"<<endl;

if ((n > 0) && !( n % 2 )) // check if integer is positive and even
cout<<"integer is positive even"<<endl;
else if ((n < 0) && !(n % 2)) // check if integer is negative and even
cout<<"integer is negative even"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}


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