-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1050.c
45 lines (39 loc) · 863 Bytes
/
1050.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
#include <stdio.h>
#include <stdlib.h>
#define N 10
/********** Specification of transpose **********/
void Transpose(void *a, int n)
/* PreCondition:
a is beginning address of a square matrix, n is the number of rows for the matrix, no more than 80.
PostCondition:
the matrix is transposed
*/
{
int z;
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
z = *((int*)a+i*n+j);
*((int*)a+i*n+j) = *((int*)a+j*n+i);
*((int*)a+j*n+i) = z;
}
}
}
/*swap(int *x, int *y)
{
int *z;
*z = *x;
*x = *y;
*y = *z;
}*/
int main()
{ int *a,n,i; scanf("%d",&n);
a=(int*)malloc(n*n*sizeof(int));
for (i=0;i<n*n;i++) scanf("%d",a+i);
Transpose(a,n);
for (i=0;i<n*n;i++)
{ printf("%d ",a[i]); if ((i+1)%n==0) printf("\n"); }
free(a);
return 0;
}