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";
Comments
Leave a comment