Row-wise addition in Matrix by R4R Team

Matrix:
-Multidimensional Array
-Matrix consist of the rows and columns.

Syntax-
array[row][column]
//Martix with numbers of rows and columns

Example-
Matrix is:
1 2
4 3
Sum of first row is 3
Sum of second row is 7

program-

#include< stdio.h>
int main()
{
int a[10][10],r,c,i,j,sum=0;
printf("Enter rows and columns in matrix\n");
scanf("%d%d",&r,&c);
printf("Enter %d number in matrix\n",r*c);
//input in matrix
for(i=0;i< r;i++){
for(j=0;j< c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Matrix is\n");
for(i=0;i< r;i++){
for(j=0;j< c;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
//Now find sum
for(i=0;i< r;i++)
{
sum=0;
for(j=0;j< c;j++)
{
sum=sum+a[i][j];
}
printf("Sum of %d row in Matrix is %d ",i+1,sum);
}
}


output-

Enter rows and columns in matrix
2 3
Enter 6 number in matrix
1 2 3 4 5 6
Matrix is
1 2 3
4 5 6
Sum of 1 row in Matrix is 6
Sum of 2 row in Matrix is 15




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!