Writing a program that contains a 5x5 array and then prints the row totas and the column totals. The row total output is fine. But the output of the column total is wrong. The total after each individual column is added to the variable is output rather than the actually final sum of all the columns.
Code:#include <stdio.h> intmain () { int a[5][5]; int row_tot = 0, i = 0, j = 0, col_tot= 0; for (i = 0; i < 5; i++){ printf("Enter row %d: ", i + 1); for (j = 0;j < 5; j++){ scanf("%d", &a[i][j]); } } printf("\n\nRow totals: "); for (i = 0; i < 5; i++){ row_tot= 0; for (j = 0; j < 5; j++){ row_tot+= a[i][j]; printf("%d ", row_tot); } } printf("\nColumn totals: "); for (j = 0; j < 5; j++){ col_tot = 0; for (i = 0; i < 5; i++) { col_tot += a[i][j]; printf("%d ", col_tot); } } return 0; }