-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2_Drot.c
61 lines (53 loc) · 962 Bytes
/
2_Drot.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
54
55
56
57
58
59
60
61
//a program of 2-D array rotation by 90 degree
/*
input:
3
1 2 3
4 5 6
7 8 9
output:
7 4 1
8 5 2
9 6 3
*/
#include<stdio.h>
#include<stdlib.h>
int size;
void swap(int **a)
{
int temp;
for(int i=0;i<size/2;i++)
for(int j=i;j<size-1;j++)
{
temp=a[i][j];
a[i][j]=a[size-1-j][i];
a[size-1-j][i]=a[size-1-i][size-1-j];
a[size-1-i][size-1-j]=a[j][size-1-i];
a[j][size-1-i]=temp;
}
}
void print(int **a)
{
for(int i=0;i<size;i++){
for(int j=0;j<size;j++)
printf("%d ",*(*(a+i)+j));
printf("\n");
}
}
int main()
{
int n;
scanf("%d",&n);
size=n;
int **a=(int **)malloc(sizeof(int *)*n);
for(int i=0;i<n;i++)
*(a+i)=(int *)malloc(sizeof(int)*n);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",(*(a+i)+j));
swap(a);
print(a);
}
// what i have learnt
/*
*/