Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

C++:
01 bool palin(int x)
02 {
03     if(x<0)
04         return false;
05 
06     int t=1;
07     while((x/t)>=10){
08         t=t*10;
09     }
10     while(x>=10){
11         int r=x%10;
12         int l=x/t;
13         if(l!=r)
14             return false;
15         x=(x%tr)/10;
16         t=t/100;
17     }
18     return true;
19 }
Advertisements
This entry was posted in Number trick. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s