Archived

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

Need help with arrays...C-Language.

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites