Saturday, 20 December 2014

Find Palindrome number in c++

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int palindrome, reverse=0;
  6.     cout<<"Enter number:  ";
  7.     cin>>palindrome;
  8.     int num=0,key=palindrome;
  9. for(int i=1;palindrome!=0;i++){

  10.     num=palindrome%10;
  11.     palindrome=palindrome/10;
  12.     reverse=num+(reverse*10);
  13.               }

  14.    if(reverse==key){
  15.    cout<<key<<" is a Palindrome Number";
  16.             }
  17.             else{
  18.    cout<<key<<"is NOT a Palindrome Number";
  19.             }
  20. return 0;
}

No comments:

Post a Comment