Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C function (not a whole program) called sumDiff(). The function should t

ID: 3718101 • Letter: W

Question

Write a C function (not a whole program) called sumDiff(). The function should take two parameters, a and b, with each being a 2D arrays of ints. Both arrays have a fixed size, with the number of rows and columns defined by the following constants:

#define ROWS 15

#define COLS 15

Your function should: • Add each original element of b to the corresponding original element (at the same row and column) of a, storing the result in a. • Subtract each original element of b from the corresponding original element of a, storing the result in b. That is, after the function runs, a should contain the sum of the original arrays (element-by-element), while b should contain the difference. The function should not return any value.

Explanation / Answer

void sumDiff(int a[][COLS] , int b[][COLS])

{

    int i, j;

   

    // traverse rows

    for( i = 0 ; i < ROWS ; i++ )

    {

        // traverse columns

        for( j = 0 ; j < COLS ; j++ )

        {

            // store the original value of a

            int temp_a = a[i][j];

           

            // store the original value of b

            int temp_b = b[i][j];

           

            a[i][j] = temp_a + temp_b;

           

            b[i][j] = temp_a - temp_b;

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote