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.
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started