#include<stdio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char a[50],b[50];
int l,l1,i=0,c=0,x[20],y[20],n=0,m=0,j=0,max;
int index=0,index1=0,flag=0,d;
clrscr();
puts("\nenter the first string");
gets(a);
puts("\nenter the second string");
gets(b);
l=strlen(a);
l1=strlen(b);
while(i<l)
{
while(a[i]!=' ')
{
if(a[i]=='\0')
break;
c++;
i++;
}
x[n]=c;
n++;
i++;
c=0;
}
while(j<l1)
{
while(b[j]!=' ')
{
if(b[j]=='\0')
break;
c++;
j++;
}
y[m]=c;
m++;
j++;
c=0;
}
p:
max=x[0];
index=0;
for(i=1;i<n;i++)
{
if(max<x[i])
{
max=x[i];
index=i;
}
}
if(max==0)
{
printf("\ntheir are no common sub strings");
getch();
exit(0);
}
index1=0,flag=0;
z:
for(i=index1;i<m;i++)
{
if(max==y[i])
{
index1=i;
flag=1;
break;
}
}
if(flag==0)
{
x[index]=0;
goto p;
}
i=0,c=0;
while(c<index)
{
if(a[i]==' ')
c++;
i++;
}
j=0,c=0;
d=i;
while(c<index1)
{
if(b[j]==' ')
c++;
j++;
}
while(i<(max+d))
{
if(a[i]!=b[j])
{
index1++;
flag=0;
goto z;
}
i++;
j++;
}
printf("\nthe required largest common substring is\n");
for(i=d;i<(max+d);i++)
printf("%c",a[i]);
x[index]=0;
index++;
while(index<n)
{
if(x[index]==max)
{
index1=0;
goto z;
}
index++;
}
getch();
}