Question: Help needed. Please re-correct my code to print right results. The result I want to print out is blow: but my code can only print

Help needed. Please re-correct my code to print right results. The result I want to print out is blow:

Help needed. Please re-correct my code to print right results. The result

but my code can only print out.

I want to print out is blow: but my code can only

My C code is blow, the code should dynamically print results when matrix and word1,word2 are changing:

#include #include

int main () {

char matrix[7][9]={{0,1,2,3,4,5,6,7,8,9},{1,0,1,2,3,4,5,6,7,8},{2,1,0,1,2,3,4,5,6,7}, {3,2,1,0,1,2,3,4,5,6},{4,3,2,1,0,1,2,3,4,5},{5,4,3,2,1,1,2,3,4,5},{6,5,4,3,2,2,2,3,3,4}, {7,6,5,4,3,3,3,3,4,4}}; char word1[100]="someone"; char word2[100]="something"; int len1; int len2; len1=strlen(word1); len2=strlen(word2); char path1[100]; char path2[100]; char cost[100]; int i,j;

int max(int a,int b) { return a>b?a:b; } for(i=0;i=1;i--) { for(j=len2;j>=1;j--) { if((matrix[i][j]==matrix[i-1][j-1])&&word1[i-1]==word2[j-1]) { path1[max(i,j)-1]=word1[i-1]; path2[max(i,j)-1]=word2[j-1]; cost[i-1]='.'; } if(matrix[i][j]==matrix[i-1][j-1]+1) { path1[max(i,j)-1]=word1[i-1]; path2[max(i,j)-1]=word2[j-1];

}

if((matrix[i][j]==matrix[i-1][j]+1)&&(matrix[i][j]!=matrix[i-1][j-1]+1)) { path1[max(i,j)-1]=word1[i-1]; path2[max(i,j)-1]='-';

} if((matrix[i][j]==matrix[i][j-1]+1)&&(matrix[i][j]!=matrix[i-1][j-1]+1)&&(matrix[i][j]!=matrix[i-1][j]+1)) { path1[max(i,j)-1]='-'; path2[max(i,j)-1]=word2[j-1];

} }

} printf("Alignment: ");

for(i=0;i Alignment: S O Im e - s o met h in g --On e Alignment: S O Im e - s o met h in g --On e

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!