TotalUp Array

Hey, guys, I got this code written but I don't know how to following things:
a. Total up the numbers in each row and print the total at the end of the row
b. Total up the numbers in each column and print the columns total below each column
c. Total up all the numbers in the array and print this total in the bottom right corner of the print

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/******************************************
* library includes
******************************************/
#include "stdafx.h"
#include <iostream> // needed for I/O

/******************************************
* pre-processor
******************************************/
#define PI 3.14159
using namespace std;

/****************************************
* function prototypes
****************************************/


/*****************************************
* main() - the function that executes
*****************************************/
int main()
{
/*******************************
* local variables *
*******************************/
int row = 0; // row counter
int col = 0; // column counter

int maxRow = 20; // max rows
int maxCol = 10; // max columns

int intArray [20][11]; // 2 dimensional array of ints

// load the array with random numbers from 0 ~ 9
for(row=0; row<maxRow; row++)
{
for(col=0; col<maxCol; col++)
{
intArray[row][col] = rand() % 10;
}
}

// print out the initial array
cout << "\n\n";
cout << "*******************\n";
cout << "* initial array *\n";
cout << "*******************\n";
for(row=0; row<maxRow; row++)
{
cout << "\n";
for(col=0; col<maxCol; col++)
{
cout << intArray[row][col] << " ";
}
}
cout << "\n\n";

system("pause");
return 0;
} // end main 




Right now output for this code is this:

*******************
* initial array *
*******************

7 9 3 8 0 2 4 8 3 9
0 5 2 2 7 3 7 9 0 2
3 9 9 7 0 3 9 8 6 5
7 6 2 7 0 3 9 9 9 1
7 2 3 6 5 5 8 1 4 7
1 3 8 4 8 0 4 6 0 3
2 6 9 4 1 3 7 8 8 3
8 1 5 3 5 4 3 6 5 9
5 4 9 1 7 5 5 4 1 8
8 3 5 2 2 6 6 7 8 4
1 7 1 8 7 8 7 7 4 4
9 1 5 5 5 8 2 9 8 2
0 7 4 8 5 8 3 0 6 2
2 5 2 2 7 1 5 2 1 1
0 1 8 7 6 0 0 9 5 6
2 8 5 9 4 3 9 0 5 6
3 6 3 0 8 4 0 4 6 4
6 4 3 8 4 0 0 9 3 7
5 7 2 9 7 5 6 5 3 0
4 8 5 5 5 4 2 1 9 2

But I want the one output as above and second is like this but with sum of the row and column and total array


*******************
* Summed up array *
*******************

7 9 3 8 0 2 4 8 3 9
0 5 2 2 7 3 7 9 0 2
3 9 9 7 0 3 9 8 6 5
7 6 2 7 0 3 9 9 9 1
7 2 3 6 5 5 8 1 4 7
1 3 8 4 8 0 4 6 0 3
2 6 9 4 1 3 7 8 8 3
8 1 5 3 5 4 3 6 5 9
5 4 9 1 7 5 5 4 1 8
8 3 5 2 2 6 6 7 8 4
1 7 1 8 7 8 7 7 4 4
9 1 5 5 5 8 2 9 8 2
0 7 4 8 5 8 3 0 6 2
2 5 2 2 7 1 5 2 1 1
0 1 8 7 6 0 0 9 5 6
2 8 5 9 4 3 9 0 5 6
3 6 3 0 8 4 0 4 6 4
6 4 3 8 4 0 0 9 3 7
5 7 2 9 7 5 6 5 3 0
4 8 5 5 5 4 2 1 9 2
Last edited on
Topic archived. No new replies allowed.