#### Archived

This topic is now archived and is closed to further replies.

# Need help with arrays...C-Language.

This topic is 5378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok. I''m starting to get teach myself arrays for C-language. What I''m trying to do is creat a proram that reads a 5 x 5 array of integers and then prints the row sums and the column sums. It should look something like this when coded properly: Row1: 1 1 1 1 1 Row2: 2 2 2 2 2 Row3: 3 3 3 3 3 Row4: 4 4 4 4 4 Row5: 5 5 5 5 5 Row Totals: 5 10 15 20 25 Colum Totals: 15 15 15 15 15 I got the part where it shows the numbers that were inputted to the array. I think that to total up each row and column is to use a for loop like this: for(row1=0; row1<=ROWS; row1++){ for(row2=0; row2<=COLS; row2++){ total += a[row1][row2]; } printf("Total for Row %d is: %d", row1+1, total); printf("\n"); } However, that adds up all of the numbers!! For now, I want to tackle it in adding the rows. If I get that working right then the columns will be done faster.

##### Share on other sites
It totals up all the numbers because you do not set total to 0 when you move onto the next row.

"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

##### Share on other sites
I was just about to say that I figured it out. And turns out someone beat me to it. Thanks for your help. Now I gotta figure out how to read each colum now and by the looks of it, I''ll have to do the same but maybe use another type of loop.

##### Share on other sites
ok i got the whole thing working now.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633725
• Total Posts
3013568
×