The Next Palindrome
QUESTION:
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K, write the value of the smallest palindrome larger than K to output.
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K, write the value of the smallest palindrome larger than K to output.
Input
The first line contains an integer, which corresponds to K. Assume that K is less than 200000.
Output
Output consists of a single integer, which corresponds to the smallest palindrome larger than K.
Sample Input 1:
808
Sample Output 1:
818
Sample Input 2:
2133
Sample Output 2:
2222
SOLUTION:
#include<stdio.h>
int main()
{
long int num,pa=0,rem,temp;
scanf("%ld",&num);
while(num!=pa)
{
num=num+1;
temp=num;
pa=0;
while(temp!=0)
{
rem=temp%10;
pa=rem+pa*10;
temp=temp/10;
}
}
printf("%ld",pa);
return 0;
}
Comments
Post a Comment