You are on page 1of 1

#include<stdio.

h>
main()
{
char s[100];
printf("enter the string:\n");
gets(s);
int low,upp,p_len=0;
int p_strt,p_end;
int n = strlen(s);
if(n%2==0)
{
low = n/2-1;
upp = n/2;
}
else
low = upp = n/2;
int i;
while (low>=0 && upp<n)
{
while(s[low]==s[upp])
{
upp++;
low--;
}
if(p_len<(upp-low-1))
{
p_len = upp-low-1;
p_strt = low +1;
p_end = upp-1;
}
low = upp;
}
if(p_len!=1){
printf("the longest palindrome is ");
for(i=p_strt;i<=p_end;i++)
printf("%c",s[i]);
}
else
printf("palindrome doesnt exist");
puts("\n");
getch();
}

You might also like