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
Code:
#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; }
This comment has been removed by the author.
ReplyDeleteThis will not work if a single digit is the input.
ReplyDeleteadd following code:
Deleteif(a>0 && a<=9){
printf("11");
}
you check reverse and num is same after that once again asign reverse=0;It works correctly
ReplyDeletewhy pa=0;
ReplyDelete