63 152
Assignments Done
99,3%
Successfully Done
In July 2018

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
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions