C Program to Find Row Sum and Column Sum of Matrix
Write C Program to Find Row Sum and Column Sum of Matrix
// C Program to Find Row Sum and Column Sum of Matrix #include <stdio.h> int main() { int i,j ,sum = 0; int A[3][3] = { {1, 2, 0}, {4, 0, 6}, {7, 8, 0} }; printf("Matrix A :--> \n"); for(i = 0;i < 3; i++) { for( j = 0; j < 3; j++) { printf("%d ", A[i][j]); } printf("\n"); } for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { sum = sum + A[i][j]; } printf("\nSum of row %d :--> %d", i, sum); sum = 0; } printf("\n"); for(i = 0;i < 3; i++) { for(j = 0;j < 3; j++) { sum = sum + A[j][i]; } printf("\nSum of Column %d :--> %d", i, sum); sum=0; } return 0; }
Output:
Matrix A :-->
1 2 0
4 0 6
7 8 0
Sum of row 0 :--> 3
Sum of row 1 :--> 10
Sum of row 2 :--> 15
Sum of Column 0 :--> 12
Sum of Column 1 :--> 10
Sum of Column 2 :--> 6