Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this question about how to program a palidrome of numbers in C+

ID: 2246656 • Letter: I

Question

I need help with this question about how to program a palidrome of numbers in C++. The program steps say that numbers with fewer than 5 digits are automtically "padded" with leading zeros. So if you enter 0, that gets treated as 00000, and it's a palindrome. But 1 gets treated as 00001, and it's not. 100 is, because that's 00100. In other words, the program needs to input the zeros and display to the user. Also, the program needs to use a sentinel-controlled loop to repeat the palindrome determination until the user enters a lowercase or uppercase Q to quit. Thanks.

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

Explanation / Answer

#include <iostream>

#include <cstdio>

#include <vector>

#include<algorithm>

using namespace std;

int main() {

int value;

cout<<"Enter value ";

cin>>value;

  

vector<int> k;

vector<int> z;

int j=5;

while(j!=0){

k.push_back(value%10);

value /= 10;

j--;

}

cout<<endl;

cout<<5<<endl;

int i=4;

  

while(i>=0){

z.push_back(k[i]);

i--;

}

reverse(k.begin(),k.end());

if( z == k){

cout<<"Palindrome"<<endl;

}

else{

cout<<"not palindrome"<<endl;

}

cout<<endl;

return 0;

}