Skip to content

Instantly share code, notes, and snippets.

@ajaynitt
Created September 30, 2014 13:06
Show Gist options
  • Save ajaynitt/2ea420f7af2f0033ee80 to your computer and use it in GitHub Desktop.
Save ajaynitt/2ea420f7af2f0033ee80 to your computer and use it in GitHub Desktop.
if an integer is Palindrome or not
/*Check if a number is Palindrome
*/
#include <iostream>
#include<cstring>
using namespace std;
#include<cmath>
bool isPalindrome(int n)
{
int ndigit=0;
int num=n;
while(num>0) {ndigit++;num/=10;}
int factor=pow(10.0,1.0*(ndigit-1));
num=n;
while(n>0){
if(n/factor == n%10)
{n=n%factor;
n=n/10;
factor=factor/100;
}
else return 0;
}
return 1;
}
int main()
{
int n;
cin>>n;
if(isPalindrome(n)) cout<<"Yes";
else cout<<"No";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment