#include<stdio.h>
#include<string.h>
int check_pal(char str_check[],int i,int j)
{
int k,flag=0;
for(k=0;k<=(j-i)/2;k++)
{
if(str_check[i+k]!=str_check[j-k])
{
flag=1;
break;
}
}
if(flag==1)
{
return -1;
}
else
{
return j-i+1;
}
}
void main()
{
char *str="vhgfhjggjjggknkjnk";
int i,j,count=0,max=0,start,end,length;
for(i=0;str[i]!='\0';i++)
{
for(j=i+1;str[j]!='\0';j++)
{
if(str[i]==str[j])
{
length=check_pal(str,i,j);
if(length>max)
{
start=i;
end=j;
max=length;
}
}
}
}
printf("Length =%d\n",max);
printf("Longest substring is as follows ");
for(i=start;i<=end;i++)
{
printf("%c",str[i]);
}
}
output
Longest substring is as follows ggjjgg
#include<string.h>
int check_pal(char str_check[],int i,int j)
{
int k,flag=0;
for(k=0;k<=(j-i)/2;k++)
{
if(str_check[i+k]!=str_check[j-k])
{
flag=1;
break;
}
}
if(flag==1)
{
return -1;
}
else
{
return j-i+1;
}
}
void main()
{
char *str="vhgfhjggjjggknkjnk";
int i,j,count=0,max=0,start,end,length;
for(i=0;str[i]!='\0';i++)
{
for(j=i+1;str[j]!='\0';j++)
{
if(str[i]==str[j])
{
length=check_pal(str,i,j);
if(length>max)
{
start=i;
end=j;
max=length;
}
}
}
}
printf("Length =%d\n",max);
printf("Longest substring is as follows ");
for(i=start;i<=end;i++)
{
printf("%c",str[i]);
}
}
output
Longest substring is as follows ggjjgg
No comments:
Post a Comment