File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ //WAP to find sum of rows and columns of a matrix
2
+
3
+ #include <stdio.h>
4
+
5
+ void main (){
6
+ int m ,n ;
7
+ printf ("Enter the number of rows and columns of the matrix: \n" );
8
+ scanf ("%d %d" ,& m ,& n );
9
+ int A [m ][n ];
10
+ for (int i = 0 ;i < m ;i ++ ){
11
+ for (int j = 0 ;j < n ;j ++ ){
12
+ printf ("Enter the element: \n" );
13
+ scanf ("%d" ,& A [i ][j ]);
14
+ }
15
+ }
16
+ printf ("The matrix is: \n" );
17
+ for (int i = 0 ;i < 0 ;i ++ ){
18
+ for (int j = 0 ;j < n ;j ++ ){
19
+ printf ("%d\t" ,A [i ][j ]);
20
+ }
21
+ printf ("\n" );
22
+ }
23
+ printf ("The sum of the columns is:\n" );
24
+ for (int i = 0 ;i < m ;i ++ ){
25
+ int sum = 0 ;
26
+ for (int j = 0 ;j < n ;j ++ )
27
+ sum = sum + A [i ][j ];
28
+ printf ("%d\t" ,sum );
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ //transpose general
2
+ #include <stdio.h>
3
+
4
+ void main () {
5
+ int i ,j ,m ,n ;
6
+ printf ("Enter the number of rows and columns od the matrix: \n" );
7
+ scanf ("%d,%d" ,& m ,& n );
8
+ int A [m ][n ], B [n ][m ];
9
+ printf ("Enter the elements of the matrix: \n" );
10
+ for (i = 0 ;i < m ;i ++ ) {
11
+ for (j = 0 ;j < n ;j ++ ) {
12
+ printf ("Enter element: \n" );
13
+ scanf ("%d" ,& A [i ][j ]);
14
+ }
15
+ }
16
+ for (i = 0 ;i < m ;i ++ ) {
17
+ for (j = 0 ;j < n ;j ++ )
18
+ B [j ][i ]= A [i ][j ];
19
+ }
20
+ printf ("The matrix is: \n" );
21
+ for (i = 0 ;i < m ;i ++ ) {
22
+ for (j = 0 ;j < n ;j ++ )
23
+ printf ("%d\t" ,A [i ][j ]);
24
+ printf ("\n" );
25
+ }
26
+ printf ("The transpose of the matrix is: \n" );
27
+ for (i = 0 ;i < n ;i ++ ) {
28
+ for (j = 0 ;j < m ;j ++ )
29
+ printf ("%d\t" ,B [i ][j ]);
30
+ printf ("\n" );
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments