# Thread: How to calc Two array

1. ## How to calc Two array

Hi,
I have like array
a[2][3]+b[2][3]=c[2][3]
can some tell how to calc both in carray
=====================

2. I'm not quite sure if this is what you're asking, so I'll explain in a little more detail.

You say you have two arrays, and you want to add each element of the similar indexes to a new array total. Like for instance if you had two weeks of data by day, you'd have each week and a total
Code:
```     Week 1       Week 2       Total
Sun    50           62          112

Mon    66           61          127

Tue    45           53           98

Wed    57           60          117

etc...```
If this is the case, then you need to loop through your arrays and total each index at one time.
Code:
```for(int i = 0; i < ROW; i++)
for(int j = 0; j < COL; j++)
arryTot[i][j] = arry1[i][j] + arry2[i][j];```

3. Thanks for ur .....
Plz I need some like this.

A [1][1] b[1][1] C
1 2 2 6 3 8
4 5 + 4 2 = 8 7

I need calc A array + arryB result in C array.
for(i=0;i<2;i++)

for(j=0;j<2;j++)
cin>>[i][j] /* this will add element of A

for(i=0;i<2;i++)
for(j=0;j<2;j++)
cin>b[i][j];/*** this i am add B elemnt is that correct.

now
How I will sum a[][]+b[][]
then save in c[][]
Ineed that loop

for I need some like c

thx

4. Code:
```    const int arr_size = 2;
const int arr_size2 = 3;
int a[arr_size][arr_size2] = {2, 3, 5, 6, 8, 6};
int b[arr_size][arr_size2] = {1, 4, 7, 5, 4, 1};

int c[arr_size][arr_size2];

for (int i = 0; i != arr_size; ++i) {
for (int z = 0; z != arr_size2; ++z) {
c[i][z] = a[i][z] + b[i][z];
}
}```

5. Thanks alot.
I will try that.

Final.
Plz

I have this array
A
1 5 6
2 7 8
3 4 2

exchnage
with first line with last to be liker this

3 4 2

2 7 8

1 5 6

Thax-Iraq

6. Did you try to sort the array in decending order with any one of the sort algorithms? My suggestion of course, hinges on the fact that an array[x][y] is also an array[xy], and sorting the first row would result in an order like the one you want.

7. friend
Sort wll not solve my problem in my example sort will be I want code all
example.

thx

8. Show your attempt at writing the exchange code. It is very much like a simple swap, except you would want to loop through the columns of the rows being swapped, rather than just a simple assignment.