Next Number Palindrome ID:226
Given a number N, the program must print the next palindromic number P.
Boundary Conditions:
9 < N < 100000
Input Format:
First line will contain the number N
Output Format:
First line will contain the next palindromic number P.
Sample Input/Output:
Example 1:
Input:
909
Output:
919
Example 2:
Input:
2131
Output:
2222
PROGRAM IN C:
#include<stdio.h>
#include <stdlib.h>
int reverse(int);
int main()
{
int n;
scanf("%d",&n);
palindrome(n);
}
int palindrome(int x)
{
int i,f=0,rev;
for(i=x+1;f==0;i++)
{
rev=reverse(i);
if(i==rev)
{
printf("%d",i);
f++;
}
}
}
int reverse(int i)
{
int r,revno=0;
while(i>0)
{
r=i%10;
revno=revno*10+r;
i=i/10;
}return revno;
}
Comments
Post a Comment