1/* C Program to find Sum of columns in a Matrix */
2
3#include<stdio.h>
4
5int main()
6{
7 int i, j, rows, columns, a[10][10], Sum;
8
9 printf("Please Enter Number of rows and columns : ");
10 scanf("%d %d", &i, &j);
11
12 printf("Please Enter the Matrix Row and Column Elements \n");
13 for(rows = 0; rows < i; rows++)
14 {
15 for(columns = 0; columns < j; columns++)
16 {
17 scanf("%d", &a[rows][columns]);
18 }
19 }
20
21 for(rows = 0; rows < i; rows++)
22 {
23 Sum = 0;
24 for(columns = 0; columns < j; columns++)
25 {
26 Sum = Sum + a[columns][rows];
27 }
28 printf("The Sum of Column Elements in a Matrix = %d \n", Sum );
29 }
30
31 return 0;
32}
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
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 (j = 0; j < n; ++j)
25 {
26 for (i = 0; i < m; ++i)
27 {
28 sum = sum + matrix[i][j];
29 }
30
31 printf("Sum of the %d column is = %d\n", j+1, sum);
32 sum = 0;
33 }
34}
35
36