Question: This sum function adds two 2D arrays(square matrices) A and B and stores the values in a new 2D array. (x1, y1) and (x2,y2) are

This sum function adds two 2D arrays(square matrices) A and B and stores the values in a new 2D array. (x1, y1) and (x2,y2) are the indices of matrix A and B, respectively, at which the function starts adding the matrices; also, n is the size of the square matrices. Consequently, the parameters x1, y1, x2, and y2 must be incremented accordingly to calculate the next index (ie. from A[0][0] to A[0][1] and so on).

I would like to know how to finish implementing the function. I have already tried to increment these parameters within the for loops but this ends up causing an error. Also, the current code prints out the same value for each index of the matrix.

This sum function adds two 2D arrays(square matrices) A and B and

75 publid int[][] sum(int[][] A, int [ ] [ ] B, int xl, int yl, int x2, int y2, int n) { int[][] res = initMatrix (n); // n = size of square matrix for (int i = 0; i

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!