How can I accumulate the values in one dimension of a 2-d array, without accumulating the values from both dimensions? I know that in order to access a 2-d array i need to type myarray[2][2]. But is there a way of accessing ONE dimension and accumulating the values for just that dimension only?
#include <iostream>
usingnamespace std;
int main ()
{
int days [2][2] = {1,1, 1,1};
int total = 0; //accumulator for first dimension
int total1= 0; //accumulator for second dimension
for (int m = 0; m <= 29; m++)
total += days[m];
for (int n = 0; n <= 5; n++)
total1 += days[n];
cout << total1;
cout << total;
#include <iostream>
usingnamespace std;
int main ()
{
int days [2][2] = {1,1, 1,1};
int total = 0; //accumulator for first dimension
int total1= 0; //accumulator for second dimension
for (int m = 0; m <= 29; m++)
total += days[m][0];
//total += days[0][m];
//total += days[m][1]
//total += days[m][2]
for (int n = 0; n <= 5; n++)
total1 += days[n][0];
// total1 += days[0][n];
cout << total1;
cout << total;