forked from Reshma2005/ZohoEnrich
-
Notifications
You must be signed in to change notification settings - Fork 0
/
q14nxtpal.c
50 lines (46 loc) · 948 Bytes
/
q14nxtpal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<stdio.h>
#include<string.h>
int main()
{
int i=0,j,mid,n,flag=0;
char a[10];
printf("Enter the number:\n");
scanf("%s",a);
n=strlen(a);
mid=(n/2)-1;
while(i<=mid)
{
if(n%2 == 0)
{
j=i+1;
}
else
{
j=i+2;
}
if(a[mid-i] != a[mid+j])
{
if(flag == 0)
{
if(a[mid-i]>a[mid+j])
{
flag=1;
a[mid+j]=a[mid-i];
}
else
{
a[mid-i]=a[mid-i]+1;
flag=1;
a[mid+j]=a[mid-i];
}
}
else
{
a[mid+j]=a[mid-i];
}
i++;
}
}
printf("\nThe nearest palindrome is: %s\n",a);
return 0;
}