Answer to Question #341396 in C++ for Nia

Question #341396

Write a program that reads an integer and determines and prints whether it is odd or



even.



a) first the program using if statements



b) then the program using if/else statements




1
Expert's answer
2022-05-17T08:56:30-0400
#include <iostream>

using namespace std;    
    
int main()
{
    unsigned int n;
    
    cout << "Enter an integer greater than zero: ";
    cin >> n;
    
    if(n > 0)
    {    
        if(n % 2 == 1)
        {
            cout << "Odd" << endl;
        }
        else
        {
            cout << "Even" << endl;
        }
    }
}

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