-
Notifications
You must be signed in to change notification settings - Fork 110
/
transpose.c
43 lines (39 loc) · 1.05 KB
/
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
//Program to find transpose of matrix
#include <stdio.h>
int main()
{
//to declare variables
int a[10][10], transpose[10][10],rows,col;
printf("Enter rows and columns: ");
scanf("%d %d",&rows,&col);
// asssigning elements to the matrix
printf("\nEnter matrix elements:\n");
for (int i = 0; i < rows; ++i)
for (int j = 0; j < col; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
// printing the matrix a[][]
printf("\nEntered matrix: \n");
for (int i = 0; i < rows; ++i)
for (int j = 0; j < col; ++j) {
printf("%d ", a[i][j]);
if (j == col - 1)
printf("\n");
}
// to calculate transpose
for (int i = 0; i < rows; ++i)
for (int j = 0; j < col; ++j) {
transpose[j][i] = a[i][j];
}
// displaying the transpose
printf("\nTranspose of the matrix:\n");
for (int i = 0; i < col; ++i)
for (int j = 0; j < rows; ++j) {
printf("%d ", transpose[i][j]);
if (j == rows - 1)
printf("\n");
}
return 0;
//pull by GUDSKULL
}