Decisions and functions
1. (Palindromes) A palindrome is a number or a text phrase that reads
the same backward as forward. For example, each of the following five-
digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write
a program that reads in a five-digit integer and determines whether it’s
a palindrome. [Hint: Use the division and modulus operators to
separate the number into its individual digits.]
2. (Drawing Patterns with Nested for Loops) Write a program that
uses for statements to print the following patterns separately, one
below the other. Use for loops to generate the patterns. All asterisks (*)
should be printed by a single statement of the form cout << '*'; (this
causes the asterisks to print side by side). [Hint: The last two patterns
require that each line begin with an appropriate number of blanks.
Extra credit: Combine your code from the four separate problems into
a single program that prints all four patterns side by side by making
clever use of nested for loops.(a)
3. (Diamond of Asterisks) Write a program that prints the following
diamond shape. You may use output statements that print a single
asterisk (*), a single blank or a single newline. Maximize your use of
repetition (with nested for statements) and minimize the number of
output statements.