ok i have i want to summarize only the first collum

int counter=1;
int totalvertical=0;
int i=7,k=4;
int array[i][k]={random values};

for (int x=1;x<7;x++)
        {
        for (int y=0;y<4;y++)
            {
            cout<<"["<<x<<"]["<<y<<"]="<<array[i][j]<<" ";
            totalvertical=array[counter][0];
            cout<<totalvertical;
            }
        counter++;
        cout<<endl;
        }

line 12 prints me normaly what is at array[1][0] then array[2][0] then array[3][0] etc but if i change line 12 to:

totalvertical+=array[counter][0];

doesnt summarize them,why?

What do you mean by "summarize"? Can you provide a sample of intended output?

The new version of Line 11 is an accumulator, is this your intent? Are you trying to create a column of values then display the accumulated total? If so, you'll have to move Line 11 down to a different line that is after and isn't part of the display loop.

Also, at first glance, I think you need to pay closer attention to the names of the variables you are using as indexes as well. On Line 10, you have cout << ... << array[i][j] << ... . Where did the 'j' come from? It doesn't appear anywhere else in this piece of code.

Edited 5 Years Ago by Fbody: n/a

yes you are right was x and y;

what i want is if i have that
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
i want to total each collumn.
for example if i have line 12 as i have it will display 1,5,9,13,17 but if i change it to += display 4,8,20,60,112,180
when it had to display 1,6,15,28,45

Edited 5 Years Ago by ntrncx: n/a

#include <iostream>
#include <stdlib>

int main ()  {
   int arr[7][4];
   int sum[4];
   memset (&arr,0,sizeof(arr));
   memset (&sum,0,sizeof(sum));
   int nbs=0;


   for (int x=0;x<7;x++)  {
      for (int y=0;y<4;y++,nbs++)  {
         arr[x][y]=nbs;
       }
    }

   for (int x=0;x<4;x++)  {
      for (int y=0;y<7;y++)  {
         sum[x]+=arr[y][x];
         std::cout << arr[y][x] << "\n";
       }
      std::cout << sum[x] << "\n";
    }
   
 }
Comments
My word, you're dense! I'm amazed you haven't been banned. Knock this off. :(

thanks caut_baia but i want to understand the why,not to get the solution.

It is really simple.It's like computing the inverse of a matrix by just swapping rows for columns and then summing up each row

thanks but my question was why mine is not working.i understand your way but i cant understand why mine is not working.since looks logical.

since the total variable is 0 and += suppose to add to total.
why is not doing it?

sorry solved :P but i was asking only for that

It is really simple.It's like computing the inverse of a matrix by just swapping rows for columns and then summing up each row

but still didnt took answer about mine why didnt worked out :(
edited*

Edited 5 Years Ago by ntrncx: n/a

Say you have a matrix :

1 2 3 4
5 6 7 8
9 10 11 12

It's transpose is
1 5 9
2 6 10
3 7 11
4 8 12

So by changing its form it becomes easier to compute the columns in the initial form by summing the rows in the second form.That is what happens in the second loop i wrote above.Hope i made myself clear

no its ok,i understood that thanks again the guy above was right i was a bit no sense :P

This question has already been answered. Start a new discussion instead.