135. C Program to Find Row and Column Elements of a given matrix.
How does this program work?
- In this programme you will learn about how to find row sum and column sum of matrix using C Language.
- variables are stored in array.
- And then by using the for loop find the elements.
Here is the code
#include <stdio.h>
int main(void)
{
static int array [10][10];
int i, j, m, n, sum = 0;
printf("Enter the order of the matrix\n");
scanf("%d %d", &m, &n);
printf("Enter the co-efficients of the matrix\n");
for (i = 1; i <= m; ++i)
{
for (j = 1; j <= n; ++j)
{
scanf("%d", &array[i][j]);
}
}
//Compute sum of rows
for (i = 1; i <= m; ++i)
{
for (j = 1; j <= n; ++j)
{
sum = sum + array[i][j] ;
}
printf("Sum of the %d row is = %d\n", i, sum);
sum = 0;
}
sum = 0;
//Compute Sum of columns
for (j = 1; j <= n; ++j)
{
for (i = 1; i <= m; ++i)
{
sum = sum + array[i][j];
}
printf("Sum of the %d column is = %d\n", j, sum);
sum = 0;
}
return 0;
}