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;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.