find sum of individual column of a matrix in c
/* C Program to find Sum of columns in a Matrix */
#include<stdio.h>
int main()
{
int i, j, rows, columns, a[10][10], Sum;
printf("Please Enter Number of rows and columns : ");
scanf("%d %d", &i, &j);
printf("Please Enter the Matrix Row and Column Elements \n");
for(rows = 0; rows < i; rows++)
{
for(columns = 0; columns < j; columns++)
{
scanf("%d", &a[rows][columns]);
}
}
for(rows = 0; rows < i; rows++)
{
Sum = 0;
for(columns = 0; columns < j; columns++)
{
Sum = Sum + a[columns][rows];
}
printf("The Sum of Column Elements in a Matrix = %d \n", Sum );
}
return 0;
}
4.56
9
#include <stdio.h>
void main ()
{
int i,j,matrix[10][10],m,n,sum=0;
printf("Enter number of rows of matrix : ");
scanf("%d", &m);
printf("Enter number of columns of matrix : ");
scanf("%d", &n);
printf("\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter element of matrix [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
printf("\n");
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
sum = sum + matrix[i][j];
}
printf("Sum of the %d column is = %d\n", j+1, sum);
sum = 0;
}
}
Thank you!
9
0
4.67
6
#include <stdio.h>
void main ()
{
int i,j,matrix[10][10],m,n,sum=0;
printf("Enter number of rows of matrix : ");
scanf("%d", &m);
printf("Enter number of columns of matrix : ");
scanf("%d", &n);
printf("\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter element of matrix [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
printf("\n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
sum = sum + matrix[i][j] ;
}
printf("Sum of the %d row is = %d\n", i+1, sum);
sum = 0;
}
}
Thank you!
6
0
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
-
-
-
-
-
-