google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to find sum of rows and columns of a matrix - 2nd puc computer science

Write a c program to find sum of rows and columns of a matrix

write a c program to find sum of rows and columns of a matrix

write a c program to find the sum of each row and column of a matrix

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10][10],r,c,i,j,rsum,csum;

clrscr();

printf("Enter the order of the first matrix:\n");

scanf("%d%d",&r,&c);

printf("Enter the elements of matrix:\n");

for(i=0;i<r;i++)

for(j=0;j<c;j++)

scanf("%d",&a[i][j]);

for(i=0;i<r;i++)

{

         rsum=0;

         for(j=0;j<c;j++)

                  rsum=rsum+a[i][j];

         printf("Sum of row number %d=%d\n",i+1,rsum);

}

for(i=0;i<c;i++)

{

         csum=0;

         for(j=0;j<r;j++)

                  csum=csum+a[j][i];

         printf("Sum of column number %d=%d\n",i+1,csum);

}

getch();

}

Output:

Enter the order of the first matrix:

2                                                                              

2                                                                              

Enter the elements of matrix:                                                  

1 2                                                                            

3 4                                                                             

Sum of row number 1=3                                                          

Sum of row number 2=7                                                          

Sum of column number 1=4                                                        

Sum of column number 2=6  

Write a c program to find sum of rows and columns of a matrix Write a c program to find sum of rows and columns of a matrix Reviewed by Vision Academy on December 18, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.