Multiplying elements in a row

How would I take the results from the random numbers generated here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main() {
	
	const int row = 10;
	const int col = 5;
	int arr[row][col];

	srand(((unsigned)time(0)));
	
cout << "Original" << endl;

	for (int i = 0; i<10; i++) {
		for (int j = 0; j<5; j++) {
			arr[i][j] = 1 + rand() % 99;
			cout << setw(4) << arr[i][j] << setw(5) << " | ";
		}
		cout << endl;
	}


and multiply each row by the following row.
for example, the elements in the first row will get multiplied by the elements in the second row.

1 | 2 | 3 | 4
5 | 6 | 7 | 8
9 | 10| 11| 12

would display

5 | 12 | 21 |32
45| 60 | 77 |96

and so forth.

looks like you need to go backwards.
roughly

for(r = all the rows - 1, starting at maxrow, working backwards)
for(c = all the columns, going forward is fine)
newarray[r-1][c] = oldarray[r][c] * oldarray[r-1][c];

I think?




Topic archived. No new replies allowed.