From 0f2795cfafbf0ac8e4d91921334a7f7f8f35e64c Mon Sep 17 00:00:00 2001 From: JCMH1981 Date: Tue, 4 Jan 2022 21:53:24 -0500 Subject: [PATCH] Added exercise 2.24 --- Chapter-2/2-24.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Chapter-2/2-24.cpp diff --git a/Chapter-2/2-24.cpp b/Chapter-2/2-24.cpp new file mode 100644 index 0000000..89bdf74 --- /dev/null +++ b/Chapter-2/2-24.cpp @@ -0,0 +1,32 @@ +/* C++ How to Program, 9/E, by Paul Deitel & Harvey Deitel. + +Solution of exercise 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 modulus operator. An even number is a +multiple of two. Any multiple of two leaves a remainder of zero when divided +by 2.] + +Written by Juan Carlos Moreno (jcmhsoftware@gmail.com), 2022/01/04 */ + +#include + +using namespace std; + +int main() +{ + int number; + + cout << "Enter the number: "; + cin >> number; + + if ((number % 2) == 0) + { + cout << number << " is even.\n"; + } + if ((number % 2) != 0) + { + cout << number << " is odd.\n"; + } + + return 0; +} -- 2.11.4.GIT