# Addition of the rows and columns in an array.

• 11-14-2006
Turtal
Addition of the rows and columns in an array.
Ya, I'm still a newb...it's probly because my teacher has an extremely heavy accent and my book sucks, BUT I still try. Now my problem is trying to make a 5x5 array that adds the rows and columns. like

0 1 2 3 4 5 blah blah, but I need the user to enter the 10 numbers. so far i have
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5
5
Code:

```#include<stdio.h> int main() { int x, y, i; int A[5][5]; float sum; printf("enter 5 numbers\n"); for (x = 0; x < 5; x++)         scanf("%d", &A[x]); printf("enter 5 more\n");         for (y = 0; y < 5; y++)         scanf("%d", &A[y]);         i = -1;         while (i<5)         {                 i++;                 sum = A[x][y];         } printf("[%d][%d] = %f\n", x, y, sum); system("PAUSE"); return 0; }```
i know im not even close, but im lost. I've been reading the forums and reading my book over and over, but I can't find any good examples. Thanks for any help.
• 11-14-2006
noodles
So, do you want to add up all the elements of the array and display the sum? If yes, the following code may help:
Code:

```#include <stdio.h> int main() {         int a[5][5], sum;         int i, j;                 for (i=0; i<5; i++) /*Get values from user*/                 for (j=0; j<5; j++)                         scanf("%d", &a[i][j]);         sum = 0;         for (i=0; i<5; i++) /*Calculate sum*/                 for (j=0; j<5; j++)                         sum += a[i][j];                 return 0; }```
You can also combine the two for loops into one.
• 11-14-2006
Turtal
Im looking for more of a table, like what I had in my first post
• 11-14-2006
jimzy
Code:

```#include<stdio.h> int main() { int x, y, i, j; int A[5][5]; float sum;  // what is this for? printf("enter 5 numbers\n"); for (x = 0; x < 5; x++)         scanf("%d", &A[x][0]);  // reading rows printf("enter 5 more\n");         for (y = 0; y < 5; y++)         scanf("%d", &A[0][y]);  // reading columns /* loop to sum & display array */ for (i=0; i<5; i++) {     for (j=0; j<5; j++) {           A[i][j] = A[0][j] + A[i][0];           printf("%d ", A[i][j]);     }     printf("\n"); }   system("PAUSE"); return 0; }```
I believe this is what you're trying to achive.
• 11-14-2006
Turtal
Holy crap, thanks. I see where i've been going wrong. I appreciate the help.

It would be lovely if my teacher taught this.