Skip to content

Commit 489fdd3

Browse files
authored
added sum-rc-matrix, transpose
program to find sum of rows and columns of a matrix and transpose of a matrix
1 parent cf0efb9 commit 489fdd3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

sum-rc-matrix.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

transpose.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)