Qestion:
Write a program that reads an integer and determines and prints whether it is odd or even. (Hint: Use the modulus operator. An even number is a multiple of two. Any multiple of two leaves a remainder of zero when divided by 2.)
Answer:
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "Enter a number: ";
cin >> num;
if ( num % 2 == 0 )
cout << "The number " << num << " is even." << endl;
if ( num % 2 != 0 )
cout << "The number " << num << " is odd." << endl;
return 0;
}
No comments:
Post a Comment