1.

Write an algorithm to subtract a matrix A[4 x 4] from a matrix X[4 x 4]

Answer»

/* Read the two matrices */ 

1. for i=1 to 4 perform step 2 through 4 

2. { for j=1 to 4 perform step 3 through 4 

3. { Read A[i,j] 

4. Read B[i,j] 

/* Calculate the sum of the two and store it in third matrix C */

5. for i=1 to 4 perform step 6 through 8

{

6. for j=1 to 4 perform step 7 through 8 

7. { C[i,j]=0

8. C[i,j]=A[i,j]-B[i,j]

}

 }



Discussion

No Comment Found

Related InterviewSolutions