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

Expert's answer

/* 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;

}

#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;

}

``

## Comments

## Leave a comment