C Saved Program: calm-home

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
#include<math.h>
#include<stdlib.h>
int main(void) {
	char a[]="vishali";
	char b[]="nisha";
	int m=strlen(a);
	int n=strlen(b);
	int len=lcs(a,b,m,n);
	printf("\nthe longest sequence is %d",len);
	return 0;
}
int lcs(char a[],char b[],int m,int n)
{
    int i,j,l[m+1][n+1];
    for(i=0;i<m;i++)
    {
        fro(j=0;j<n;j++)
        {
            if(i==0||j==0)
            {
                l[i][j]=0;
                
            }
            else if(a[i-1]==b[j-1])
            {
                l[i][j]=l[i-1][j-1]+1;
            }
            else l[i][j]=max(l[i-1][j],l[i][j-1]);
        }
    }
    return l[m][n];
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs