find sum of individual row of a matrix in c

Solutions on MaxInterview for find sum of individual row of a matrix in c by the best coders in the world

showing results for - "find sum of individual row of a matrix in c"
Marc
05 Jan 2018
1#include <stdio.h>
2void main ()
3{
4    int i,j,matrix[10][10],m,n,sum=0;
5
6    printf("Enter number of rows of matrix  : ");
7    scanf("%d", &m);
8    printf("Enter number of columns of matrix  : ");
9    scanf("%d", &n);
10
11    printf("\n");
12
13    for (i = 0; i < m; i++)
14    {
15        for (j = 0; j < n; j++)
16        {
17            printf("Enter element of matrix [%d][%d]: ", i, j);
18            scanf("%d", &matrix[i][j]);
19        }
20    }
21
22    printf("\n");
23
24    for (i = 0; i < m; ++i)
25    {
26        for (j = 0; j < n; ++j)
27        {
28            sum = sum + matrix[i][j] ;
29        }
30
31        printf("Sum of the %d row is = %d\n", i+1, sum);
32        sum = 0;
33
34    }
35}
36