ARRAYS

Suppose A, B, C, and D are two-dimensional arrays , all of the same size ,and all of type double . Write a code fragment that computes D = A + B + C, where each element of D is the sum of the corresponding elements of A, B and C. Assume two integer variables numRows and numCols that denote the number of rows and columns in each matrix. Declare any other variables that you need.
Instructor Notes: For example, if A[0][0] is 1, B[0][0] is 10, and C[0][0] is -2, then the sum is 9, and you would store this sum into D[0][0]. So by corresponding elements, this means elements with the same indices r and c, as in [r][c].

NOT SURE WHAT I AM DOING WRONG, ANY HELP IS APPRECIATED.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
A[0][0] = 0;
B[0][0]= 0;
C[0][0] = 0;


for(int r=0; r<numRows; r++)
{
	for(int c=0; c < numCols ; c++ )
	{
	
		D[][] =  A[r][c]+ B[r][c] + C[r][c];
	}



}

cout << D[][];
D[r][c]
it says i need to use sum so would sum = sum + A[r][c]+B[r][c]+C[r][c]; ??

then D[r][c] == sum ??
Figured it out, thanks!
what was your final solution?
Topic archived. No new replies allowed.