-
Notifications
You must be signed in to change notification settings - Fork 2
/
transpose.c
53 lines (45 loc) · 892 Bytes
/
transpose.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
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
int main()
{
int row, col, matrix[10][10], transposed[10][10];
printf("Enter row and Column size : ");
scanf("%d %d", &row, &col);
printf("Enter the elements of matrix : \n");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
scanf("%d", &matrix[i][j]);
}
}
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
transposed[j][i] = matrix[i][j];
}
}
printf("Transposed matrix :\n");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
printf("%d ", transposed[i][j]);
}
printf("\n");
}
return 0;
}
/*
Input:
Enter row and Column size : 3 3
Enter the elements of matrix :
1 2 3
4 5 6
7 8 9
Output:
Transposed matrix :
1 4 7
2 5 8
3 6 9
*/