Well i got the class c++ programming 2 and i got my first program to write and im stuck.. on the problem here is the problem.. i would appreciate any help i can get. or any ideas of how i can accomplish this. thanks
sincerely,
Ara
Program 1,
Given the following two-dimensional 6x6 square array:
2 3 38 21 19 3
3 23 49 37 83 -7
14 37 20 2 4 22
30 2 2 3 223 22
18 43 29 37 34 23
81 34 92 73 43 32
Write a program that will compute:
The sum of each row.
The sum of each column.
The sum of the major diagonal (coordinates that satisfy r=c)
the sum of the minor diagonal (coordinates that satisfy 6-r=c)
The sum of each concentric square (i.e. all points equidistant from the border)
what i got so far. i have the rows and colums adding already i just need some help with the last three. this is what i have so far.
Code:
using namespace std;
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main () {
int a[6][6] =
{
{2, 3, 38, 21, 19, 3},
{3, 23, 49, 37, 83, -7},
{14, 37, 20, 2, 4, 22},
{30, 2, 2, 3, 223, 22},
{18, 43, 29, 37, 34, 23},
{81, 34, 92, 73, 43, 32}
};
const int csize = 6;
const int rsize= sizeof(a)/sizeof(int)/csize;
for (int r=0; r < rsize; r++ ) {
cout << setw(5) << a[r][0];
for (int c=1; c < csize; c++) { // Add a[r][c] to sum
cout << " "<< setw(rsize) <<a[r][c];
}
cout << endl;
}
for (int r=0; r < rsize; r++ ) {
int sum = 0;
for (int c=0; c < csize; c++) { // Add a[r][c] to sum
sum = sum + a[r][c];
}
cout << "Row " << r << " sum: " << sum << endl;
}
for (int c=0; c < csize; c++ ) {
int sum = 0;
for (int r=0; r < csize; r++) { // Add a[r][c] to sum
sum = sum + a[r][c];
}
cout << "Col " << c << " sum: " << sum << endl;
}
return 0;
}