Ask Question
26 May, 03:46

Write a method named matrixAdd that accepts a pair of two-dimensional arrays of integers as parameters, treats the arrays as 2D matrices and adds them, returning the result. The sum of two matrices A and B is a matrix C where for every row i and column j, Cij = Aij + Bij. You may assume that the arrays passed as parameters have the same dimensions.

+4
Answers (1)
  1. 26 May, 04:05
    0
    The code to this question can be given as follows:

    Code:

    int matrixAdd (int[][] a, int[][] b) / /defining method matrixAdd

    {

    int c[x][y]=0; //defining variable

    for (int x = 0; x
    {

    for (int y = 0; y
    {

    int c[x][y] = a[x][y] + b[x][y]; / /add array elements

    }

    }

    return c[x][y]; //return value

    }

    Explanation:

    In the above method definition code, a method "matrixAdd" is defined that contains two integer 2D arrays "a[][] and b[][]" in its parameter, and this function returns the sum of both array.

    Inside this method, another integer 2D array "c[][]" is defined that contains nothing. To add all array elements the for loop is defined, which uses the array variable "c[][]" to add all array elements and return its value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a method named matrixAdd that accepts a pair of two-dimensional arrays of integers as parameters, treats the arrays as 2D matrices ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers