Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char s1[50],s2[50];
- int i,j,len1,len2;
- printf("Enter the first string: ");
- gets(s1);
- printf("Enter the second string: ");
- gets(s2);
- len1=strlen(s1);
- len2=strlen(s2);
- int len[len1+1][len2+1];
- for(i=0;i<=len1;i++)
- {
- len[i][0]=0;
- }
- for(i=0;i<=len2;i++)
- {
- len[0][i]=0;
- }
- for(i=1;i<=len1;i++)
- {
- for(j=1;j<=len2;j++)
- {
- if(s1[i-1]==s2[j-1])
- {
- len[i][j]=len[i-1][j-1]+1;
- }
- else
- {
- if(len[i-1][j]>len[i][j-1])
- {
- len[i][j]=len[i-1][j];
- }
- else
- {
- len[i][j]=len[i][j-1];
- }
- }
- }
- }
- printf("Length: %d", len[len1][len2]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement