Help with 2d Array

Hello, my homework assignment is to create a 2 dimensional array that displays in a 10x10 table-like format after completing this assignment i must:
a) sum of each row
b) sum of each column
c) sum of every other row (vice versa with columns)
d) add diagonally
f) change the row to columns

what i have so far is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
   const int row = 10;
   const int col = 10;
   int r,c,total;
   total = 0

   int x[row][col] = { //here ive used random numbers varying between 0-9 };

   for (r=0; r<row; r++)
     {
       for(c = 0; c < col; c++)
         {
           cout <<setw(4) << x[r][c];
           total = total + x[r][c];
         }

     cout <<" = " <<total<<endl;
      }
}


furthermore, what ive tried is to do total = total + x[r][c] within (for c= 0...)
but when it is outputted it continues to add the total from before (which of course is a looping error ive made)

if anyone could walk me through step by step of this process of figuring out how to add and subtract elements within arrays, I would gladly appreciate it.

thanks.

Last edited on
Well, for starters I would create five different functions (if you are allowed to do that) and test them one by one. Your code seems right to me, but it looks like you are adding every single element in the array.
Topic archived. No new replies allowed.