-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransposition.c
More file actions
72 lines (71 loc) · 1.51 KB
/
transposition.c
File metadata and controls
72 lines (71 loc) · 1.51 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
void PrintArrayMatrix(int **array, int row, int column);
int **ArrayTransposition(int **array, int row, int column);
int main()
{
int m, n;
printf("please input m n:\n");
scanf("%d%d", &m, &n);
int a[m][n];
for (int k = 1, i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j] = k++;
}
}
printf("The Origin Array is:\n");
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
printf("%-5d ", a[i][j]);
}
printf("\n");
}
// PrintArrayMatrix((int **)a, m, n);
// ArrayTransposition(a,m,n);
{int temp;
for (int i = 1; i < m; i++)
{
for (int j = 0; j < i; j++)
{
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
}
printf("Now The Array is:\n");
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
printf("%-5d ", a[i][j]);
}
printf("\n");
}
}
void PrintArrayMatrix(int **array, int row, int column)
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
printf("%-5d\n", array[i][j]);
}
}
}
int **ArrayTransposition(int **array, int row, int column)
{
int temp;
for (int i = 1; i < row; i++)
{
for (int j = 0; j < i; j++)
{
temp = array[i][j];
array[i][j] = array[j][i];
array[j][i] = temp;
}
}
}