views:

74

answers:

2

I just need what to do to be simplified. But if you write the source code I still want to know how and what u did explained.

Write a function that sums all the integers in a matrix of integers using the following header:

const int SIZE = 4;
double sumMatrix (const double m [] [SIZE] , int rowSize, int columnSize) ; 

Write a test program that reads a 4-by-4 matrix and displays the sum of all its elements. Heres a sample run:

Enter a 4by4 matrix row by row:
1 2 3 4 [Enter]
5 6 7 8 [Enter]
9 10 11 12 [Enter]
13 14 15 16 [Enter]
Sum of the matrix is 136

A: 

Start by initializing some variable to 0. Add the value of each cell in the matrix to that number. Return the result.

Jerry Coffin
+3  A: 

Consider breaking this down into smaller problems:

  1. How do I read lines and stop at the number of lines I want?
  2. How do I take each of those lines and split them into pieces? (And make sure it's the right number of pieces.)
  3. How do I turn those strings "1" and "2" etc into integers?
  4. How do I put them into a matrix, one line at a time?
  5. How do I iterate through the rows of a matrix?
  6. And, for each row, how do I iterate through the elements?
  7. As I'm going through, how do I keep a running-total of the sum? (And what should the sum start out as, before I start?)
eruciform
0. Do I really want to do it, or would I better find somebody else to do it for me?
Igor Oks