(Palindromes) A palindrome is a number or a text phrase that reads the same backward as for- ward. 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.]

What will be an ideal response?


```
// Determine whether a number is a palindrome.
#include
using namespace std;

int main()
{
int number = 0; // user input number
int digit1; // first digit
int digit2; // second digit
int digit4; // fourth digit; don’t care about third digit
int digit5; // fifth digit
int digits = 0; // number of digits in input
// ask for a number until it is five digits
while ( digits != 5 )
{
cout << "Enter a 5-digit number: "; // prompt for a number
cin >> number; // get number

// verify if number has 5 digits
if ( number < 100000 )
{
if ( number > 9999 )
digits = 5;
else
cout << "Number must be 5 digits" << endl;
} // end if
else
cout << "Number must be 5 digits" << endl;
} // end while

// get the digits
digit1 = number / 10000;
digit2 = number % 10000 / 1000;
digit4 = number % 10000 % 1000 % 100 / 10;
digit5 = number % 10000 % 1000 % 100 % 10;

// print whether the number is a palindrome
if ( digit1 == digit5 )
{
if ( digit2 == digit4 )
cout << number << " is a palindrome!!!" << endl;
else
cout << number << " is not a palindrome." << endl;
}
else
cout << number << " is not a palindrome." << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

Tap or click the Options tab in the Backstage view to display the ____ dialog box.

A. Mail Options B. Outlook Options C. Navigation Options D. File Options

Computer Science & Information Technology

After examining Anna’s written observations about Mike Crowe’s office, use STROBE to analyze Mike as a decision maker. What differences (if any) did you see between Mike in his interview and Mike in Anna’s observations? Use two paragraphs to answer.

What will be an ideal response?

Computer Science & Information Technology

Which /etc/fstab option allows only the root user to mount the device?

A. exec B. ro C. user D. nouser

Computer Science & Information Technology

By using the tools provided, you can create custom colors as background wallpaper

Indicate whether the statement is true or false

Computer Science & Information Technology