C Online Compiler
Example: C Program to Find Sum of Each Row and Column of a Matrix
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find Sum of Each Row and Column of a Matrix #include <stdio.h> int main() { int a[10][10], i, j, x, y, sum = 0; printf("-----Enter the number of rows & columns of the matrix-----\n"); scanf("%d %d", &x, &y); printf("\n-----Enter the co-efficients of the matrix-----\n"); for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { scanf("%d", &a[i][j]); } printf("\n"); } for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { sum = sum + a[i][j] ; } printf("The Sum of the %d position row is = %d\n", i, sum); sum = 0; } printf("\n"); sum = 0; for (j = 0; j < y; ++j) { for (i = 0; i < x; ++i) { sum = sum + a[i][j]; } printf("The Sum of the %d position column is = %d\n", j, sum); sum = 0; } return 0; }
3 4 43 54 2 56 87 4 6 89 32 54 67 1
Output
Clear
ADVERTISEMENTS