Created
September 30, 2014 13:06
-
-
Save ajaynitt/2ea420f7af2f0033ee80 to your computer and use it in GitHub Desktop.
if an integer is Palindrome or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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