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
#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;
}
}
}
Comments
Leave a comment