Good day guys, I would just like to share my code and wanted to do something about it. This code shows a loop inside a loop initializing
a two-dimensional array named arr with elements [2] and [5]. Here's my code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
int arr [2] [5];
int val = 1;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 5; j++)
{
arr [i][j] = val;
cout << arr [i][j] << " ";
val++;
}
cout << endl;
}
getch ();
return 0;
}{
Now, what I wanted to do is to have an output showing the sums of each elements. Example, the above code has an output of:
1 2 3 4 5
6 7 8 9 10
I wanted to have more codes which would add up the elements 1 + 6, 2 + 7, 3 + 8, 4 + 9, 5 + 10 and produce and output:
7 9 11 13 15
Hope anyone would let me lend me their precious time and expertise for such matter. Thanks. :)