1 /*C++ How to Program, 9/E, by Paul Deitel & Harvey Deitel.
3 Solution of exercise 4.26:
4 (Palindrome Tester) A palindrome is a number or a text phrase that reads the
5 same backward as forward. For example, each of the following five-digit
6 integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that
7 reads in a five-digit integer and determines whether or not it's a palindrome.
8 [Hint: Use the division and remainder operators to separate the number into
9 its individual digits.]
11 Written by Juan Carlos Moreno (jcmhsoftware@gmail.com), 2023-03-07*/
19 int number
, inverted_number
;
20 int first_digit
, second_digit
, third_digit
, fourth_digit
, fifth_digit
;
21 int first_remainder
, second_remainder
, third_remainder
, fourth_remainder
;
23 cout
<< "Enter the number: ";
26 first_digit
= number
/ 10000;
27 first_remainder
= number
% 10000;
28 second_digit
= first_remainder
/ 1000;
29 second_remainder
= first_remainder
% 1000;
30 third_digit
= second_remainder
/ 100;
31 third_remainder
= second_remainder
% 100;
32 fourth_digit
= third_remainder
/ 10;
33 fourth_remainder
= third_remainder
% 10;
34 fifth_digit
= fourth_remainder
;
36 inverted_number
= fifth_digit
*10000 + fourth_digit
*1000 +
37 third_digit
*100 + second_digit
*10 + first_digit
;
39 //It tests whether or not the number is a palindrome
40 if (inverted_number
== number
)
42 cout
<< "The number is a palindrome." << endl
;
46 cout
<< "The number is not a palindrome." << endl
;