Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int a[10][20],i,j,r,c,rsum,csum,sum=0;
- printf("Enter the order of the matrix\n");
- scanf("%d%d",&r,&c);
- printf("Now enter the matrix.\n");
- for(i=0; i<r; i++)
- for(j=0;j<c;j++)
- scanf("%d",&a[i][j]);
- printf("The matrix is:-\n");
- for(i=0; i<r; i++)
- {
- for(j=0;j<c;j++)
- printf("%d\t",a[i][j]);
- printf("\n");
- }
- for(i=0; i<r; i++)
- {
- rsum=0;
- csum=0;
- for(j=0;j<c;j++)
- {
- rsum += a[i][j];
- csum += a[j][i];
- sum += a[i][j];
- }
- printf("\nRow %d's sum is %d\n",i,rsum);
- printf("Coloumn %d's sum is %d\n",i,csum);
- }
- printf("\nThe grand total is %d",sum);
- }
- //Output
- //Enter the order of the matrix
- //3
- //3
- //Now enter the matrix.
- //1
- //2
- //3
- //4
- //5
- //6
- //7
- //8
- //9
- //The matrix is:-
- //1 2 3
- //4 5 6
- //7 8 9
- //Row 0's sum is 6
- //Coloumn 0's sum is 12
- //Row 1's sum is 15
- //Coloumn 1's sum is 15
- //Row 2's sum is 24
- //Coloumn 2's sum is 18
- //The grand total is 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement