Check given number is palindrome or not in C++ | C++ program to check palindrome number

Program to check given number is palindrome or not

What is Palindrome Number?  (Read Here)

Code

#include <iostream>
using namespace std;


int main() {
    
    cout<<"Enter a number "<<endl;               //Requesting a Number
    int n;
    cin>>n;


    int temp=n;                                     //to store original number for future use
    int reverse=0;                                      //To store reversed number
    
    while(n>0){                                  //loop executes till the number becomes zero
        reverse=reverse*10+n%10;            //takes last digit one by one and stores
        n=n/10;                                             //eliminates last digit
    }
    
    if(temp==reverse){
        cout<<"It is a Palindrome Number"<<endl;
    }
    else{
        cout<<
"It is not a Palindrome Number"<<endl;
    }
    
    return 0;
}



Input:

Enter a number 
22

Output:

It is a Palindrome Number


Input:

Enter a number 
25

Output:

It is not a Palindrome Number

Post a Comment

0 Comments