Write a program that reads a 5 x 5 two-dimensional array of integers and then pr
ID: 3652993 • Letter: W
Question
Write a program that reads a 5 x 5 two-dimensional array of integers and then prints the row sums and the column sums: Row Totals: Column Totals: You may either initialize this array within the program or have the user type in the values at run time. This is as far as i've gotten. thank you for your help #include #include int main() { #define NUMROWS 5 #define NUMCOLS 5 int val[NUMROWS][NUMCOLS] = { 8, 4, 5, 6, 3, 10, 15, 7, 9, 1, 2, 7, 25, 34, 66, 6, 44, 12, 8, 9, 9, 5, 4, 2, 7 }; int i, j; sunrow0 = val[0][0] + val[0][1] + val[0][2] + val[0][3] + val[0][4]; sunrow1 = val[1][0] + val[1][1] + val[1][2] + val[1][3] + val[1][4]; sunrow2 = val[2][0] + val[2][1] + val[2][2] + val[2][3] + val[2][4]; sunrow3 = val[3][0] + val[3][1] + val[3][2] + val[3][3] + val[3][4]; sunrow4 = val[4][0] + val[4][1] + val[4][2] + val[4][3] + val[4][4]; sumcol0 = val[0][0] + val[1][0] + val[2][0] + val[3][0] + val[4][0]; sumcol1 = val[0][1] + val[1][1] + val[2][1] + val[3][1] + val[4][1]; sumcol2 = val[0][2] + val[1][2] + val[2][2] + val[3][2] + val[4][2]; sumcol3 = val[0][3] + val[1][3] + val[2][3] + val[3][3] + val[4][3]; sumcol4 = val[0][4] + val[1][4] + val[2][4] + val[3][4] + val[4][4]; Rtotal= (sumrow0 +sumrow1 +sumrow2 + sumrow3 + sumrow4); Ctotal = (sumcol0 + sumcol1 + sumcol2 + sumcol3+ sumcol4); printf(" ROW totals = %d", Rtotal); printf(" COLUMN totals = %d", Ctotal); getchar(); return 0; }Explanation / Answer
#include #define NUMROWS 5 #define NUMCOLS 5 int main() { int val[NUMROWS][NUMCOLS] = { 8, 4, 5, 6, 3, 10, 15, 7, 9, 1, 2, 7, 25, 34, 66, 6, 44, 12, 8, 9, 9, 5, 4, 2, 7 }; int i, j; int sumrow0 = val[0][0] + val[0][1] + val[0][2] + val[0][3] + val[0][4]; int sumrow1 = val[1][0] + val[1][1] + val[1][2] + val[1][3] + val[1][4]; int sumrow2 = val[2][0] + val[2][1] + val[2][2] + val[2][3] + val[2][4]; int sumrow3 = val[3][0] + val[3][1] + val[3][2] + val[3][3] + val[3][4]; int sumrow4 = val[4][0] + val[4][1] + val[4][2] + val[4][3] + val[4][4]; int sumcol0 = val[0][0] + val[1][0] + val[2][0] + val[3][0] + val[4][0]; int sumcol1 = val[0][1] + val[1][1] + val[2][1] + val[3][1] + val[4][1]; int sumcol2 = val[0][2] + val[1][2] + val[2][2] + val[3][2] + val[4][2]; int sumcol3 = val[0][3] + val[1][3] + val[2][3] + val[3][3] + val[4][3]; int sumcol4 = val[0][4] + val[1][4] + val[2][4] + val[3][4] + val[4][4]; int Rtotal= (sumrow0 + sumrow1 + sumrow2 + sumrow3 + sumrow4); int Ctotal = ( sumcol0 + sumcol1 + sumcol2 + sumcol3+ sumcol4); printf(" ROW totals = %d", Rtotal); printf(" COLUMN totals = %d", Ctotal); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.