How To Check Number Is Palindrome Or Not
#include<iostream>
using namespace std;
int main(){
//three varibles
//n is number entered by user i.e number to check is it palindrom or not
//reverse is reverse of n
//temp is temporary variable to hold the number
int n,reverse=0,temp;
cout<<"Enter number to check whether is it palindrome or not =";
cin>>n;
temp=n;//assing original number to temporary variable
while(temp!=0){
reverse=reverse*10;
reverse=reverse+temp%10;
temp=temp/10;
}
if(n==reverse){
cout<<endl;
cout<<"Number is palindrome";
}
else{
cout<<endl;
cout<<"Number is not palindrome";
}
}
Watch Video
No comments :
Post a Comment