forked from Sid-Sun/cPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transposeMatrix.c
43 lines (43 loc) · 954 Bytes
/
transposeMatrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Created by sids on 29/10/18.
//
#include <stdio.h>
int matrix(int i, int j);
int main(){
int i,j;
printf("Enter the rows in the 2D array.\n");
scanf("%d",&i);
printf("Enter the columns in the 2D array.\n");
scanf("%d",&j);
matrix(i,j);
return 0;
}
int matrix(int i,int j){
int array[i][j],k,l,temp,transpose[i][j];
printf("Please enter the elements.\n");
for(k=0;k<i;k++){
for(l=0;l<j;l++){
scanf("%d",&array[k][l]);
}
}
printf("The matrix is: \n");
for(k=0;k<i;k++){
for(l=0;l<j;l++){
printf("%d ",array[k][l]);
}
printf("\n");
}
for(k=0;k<i;k++){
for(l=0;l<j;l++){
transpose[l][k]=array[k][l];
}
}
printf("The transposed matrix is: \n");
for(k=0;k<i;k++){
for(l=0;l<j;l++){
printf("%d ",transpose[k][l]);
}
printf("\n");
}
return 0;
}