Answer to Question #17813 in C++ for Asma

Question #17813
1- Write a program that prompts the user to input a positive integer and then saves the number with the digits reversed into anther integer variable called Rev.
2- A number is known as palindrome number if the reverse of the digits is equal to the number itself.
Example:
Enter the Number
12621
The Reversed is: 12621
The number: 12621 is Palindrome
1
Expert's answer
2012-11-02T13:05:22-0400
#include <iostream>
#include <string>
using namespace std;
int main(){
cout<<"Enter number\n";
string a, Rev;
cin>>a;
Rev = a;
Rev.reserve();
cout<<"The reversed is: "<< Rev<<endl;
bool ok = true;
for (int i = 0 ; i < Rev.size() / 2 ; i++){
& if (Rev[i] != Rev[Rev.size()-1-i]){
& cout<<"The number "<<a<< " isn't Palindrome\n";
& ok = !ok;
& break;
& }
}
if (ok) cout<<"The number "<<a<< " is Palindrome\n";

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS