Ok This is my first post on this forum, and would really appreciate some help on an assignment...
I have a 2d array and I need to add up all the numbers within the rows and the columns of the array. I'm really not to familiar with arrays or for loops...
I apologize for not using tags/comments in the code, but I'm not really a customs to doing so.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
void call( const int [][ 6 ] );
void call( const int a[][ 6 ] )
{
for ( int i = 0; i < 5; i++ )
{
for ( int j = 0; j < 6; j++ ){
cout << a[ i ][ j ] << ' ';
}
cout << endl;
}
}
int main()
{
int array[ 5 ][ 6 ] = { { 141, 567, 434, 100, 269, 324 },
{ 578, 458, 562, 564, 305, 245 },
{ 381, 427, 561, 591, 595, 542 },
{ 427, 536, 491, 204, 502, 253 },
{ 392, 482, 521, 316, 318, 495 } };
cout << "original array" << endl;
call( array );
return 0;
}
an example out put would be this...
Example Input Table
100 101 102 103 104 105
106 107 108 109 110 111
112 113 114 115 116 117
118 119 120 121 122 123
124 125 126 127 128 129
Example Output Table with rows summed,
columns summed and the grand total printed.
100 101 102 103 104 105 615
106 107 108 109 110 111 651
112 113 114 115 116 117 687
118 119 120 121 122 123 723
124 125 126 127 128 129 759
560 565 570 575 580 585 3435