Program to check given number is palindrome or not
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
0 Comments