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
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
constint row = 10;
constint 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.
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.