Advertisement
Shailrshah

Sum of each row and coloumn and the matrix

Apr 18th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int a[10][20],i,j,r,c,rsum,csum,sum=0;
  5.     printf("Enter the order of the matrix\n");
  6.     scanf("%d%d",&r,&c);
  7.     printf("Now enter the matrix.\n");
  8.     for(i=0; i<r; i++)
  9.         for(j=0;j<c;j++)
  10.             scanf("%d",&a[i][j]);
  11.     printf("The matrix is:-\n");
  12.     for(i=0; i<r; i++)
  13.     {
  14.         for(j=0;j<c;j++)
  15.             printf("%d\t",a[i][j]);
  16.         printf("\n");
  17.     }
  18.     for(i=0; i<r; i++)
  19.     {
  20.         rsum=0;
  21.         csum=0;
  22.         for(j=0;j<c;j++)
  23.             {
  24.                 rsum += a[i][j];
  25.                 csum += a[j][i];
  26.                 sum  += a[i][j];
  27.             }
  28.         printf("\nRow %d's sum is %d\n",i,rsum);
  29.         printf("Coloumn %d's sum is %d\n",i,csum);
  30.     }
  31.     printf("\nThe grand total is %d",sum);
  32. }
  33. //Output
  34. //Enter the order of the matrix
  35. //3
  36. //3
  37. //Now enter the matrix.
  38. //1
  39. //2
  40. //3
  41. //4
  42. //5
  43. //6
  44. //7
  45. //8
  46. //9
  47. //The matrix is:-
  48. //1       2       3
  49. //4       5       6
  50. //7       8       9
  51.  
  52. //Row 0's sum is 6
  53. //Coloumn 0's sum is 12
  54.  
  55. //Row 1's sum is 15
  56. //Coloumn 1's sum is 15
  57.  
  58. //Row 2's sum is 24
  59. //Coloumn 2's sum is 18
  60.  
  61. //The grand total is 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement