1#include <stdio.h>
2int main() {
3 int a[10][10], transpose[10][10], r, c, i, j;
4 printf("Enter rows and columns: ");
5 scanf("%d %d", &r, &c);
6
7 // Assigning elements to the matrix
8 printf("\nEnter matrix elements:\n");
9 for (i = 0; i < r; ++i)
10 for (j = 0; j < c; ++j) {
11 printf("Enter element a%d%d: ", i + 1, j + 1);
12 scanf("%d", &a[i][j]);
13 }
14
15 // Displaying the matrix a[][]
16 printf("\nEntered matrix: \n");
17 for (i = 0; i < r; ++i)
18 for (j = 0; j < c; ++j) {
19 printf("%d ", a[i][j]);
20 if (j == c - 1)
21 printf("\n");
22 }
23
24 // Finding the transpose of matrix a
25 for (i = 0; i < r; ++i)
26 for (j = 0; j < c; ++j) {
27 transpose[j][i] = a[i][j];
28 }
29
30 // Displaying the transpose of matrix a
31 printf("\nTranspose of the matrix:\n");
32 for (i = 0; i < c; ++i)
33 for (j = 0; j < r; ++j) {
34 printf("%d ", transpose[i][j]);
35 if (j == r - 1)
36 printf("\n");
37 }
38 return 0;
39}
40
1The transpose of a matrix is simply a flipped version of
2the original matrix. We can transpose a matrix by switching
3its rows with its columns. We denote the transpose of matrix
4A by AT. For example, if A=[123456] then the transpose of A is
5AT=[142536].
1#include <stdio.h>
2
3void main()
4{
5 int a[10][10], transpose[10][10], m, n;
6 printf("Enter rows and columns: ");
7 scanf("%d %d", &m, &n);
8
9
10 printf("\nEnter matrix elements:\n\n");
11 for (int i = 0; i < m; ++i)
12 {
13 for (int j = 0; j < n; ++j)
14 {
15 printf("Enter element a[%d%d]: ",i, j);
16 scanf("%d", &a[i][j]);
17 }
18
19 }
20
21
22 printf("\nEntered matrix: \n");
23
24 for (int i = 0; i < m; ++i)
25 {
26 for (int j = 0; j < n; ++j)
27 {
28 printf("%d ", a[i][j]);
29 if (j == n - 1)
30 printf("\n");
31 }
32 }
33
34 for (int i = 0; i < m; ++i)
35 {
36 for (int j = 0; j < n; ++j)
37 {
38 transpose[j][i] = a[i][j];
39 }
40
41 }
42
43
44 printf("\nTranspose of the matrix:\n");
45
46 for (int i = 0; i < n; ++i)
47 {
48 for (int j = 0; j < m; ++j)
49 {
50 printf("%d ", transpose[i][j]);
51 if (j == m - 1)
52 printf("\n");
53 }
54 }
55}
56