The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Wednesday, April 4, 2012

Palindrome of Number


#include<stdio.h>

int chk_pal(long int);

int main()
{
 int t,res;
 long num;
 scanf("%d",&t);
 while(t--)
 {
  scanf("%ld",&num);
  while(num <= 1000000)
  {
   res = chk_pal(++num);
   if(res == 1)
    break;        
  }  
  if(num <= 1000000 && res == 1)
   printf("%d\n",num);
         
 }
   
 return 0;  
}

int chk_pal(long int i)
{
 long tmp,rev = 0;
 int j=0;
 tmp = i;
 while(i!=0)
 {
  rev = (long) rev*10 + (i%10);              
  i /= 10;      
 }
  if(rev == tmp)
    return 1;
  else
    return 0;  
}

No comments:

Post a Comment