Tuesday 21 July 2020

18. 2.24 (Odd or Even) Write a program that reads an integer and determines and prints whether it’s odd or even. [Hint: Use the remainder operator (%). An even number is a multiple of two. Any multiple of 2 leaves a remainder of zero when divided by 2.]

18. 2.24 (Odd or Even) Write a program that reads an integer and determines and prints whether it’s odd or even. [Hint: Use the remainder operator (%). An even number is a multiple of two. Any multiple of 2 leaves a remainder of zero when divided by 2.] 

#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