-
Notifications
You must be signed in to change notification settings - Fork 464
/
Matrix rotation ack.c
62 lines (54 loc) · 1.08 KB
/
Matrix rotation ack.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
#include<stdio.h>
int main()
{
int i, j, n, m, k, temp;
printf("Enter no of rows: ");
scanf("%d", &n);
printf("Enter no of columns: ");
scanf("%d", &m);
int a[n][m], b[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &a[i][j]);
}
}
printf("Original matrix is\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
printf("%d ", a[i][j]);
}
printf("\n");
}
/transpose/
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
b[j][i] = a[i][j];
}
}
/reverse columns/
for(i=0; i<n; i++)
{
k = n-1;
for(j=0; j<k; j++)
{
temp = b[j][i];
b[j][i] = b[k][i];
b[k][i] = temp;
k--;
}
}
printf("Matrix after 90 anticlockwise rotation\n");
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
printf("%d ", b[i][j]);
printf("\n");
}
return 0;
}