-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday076.c
92 lines (76 loc) · 2.14 KB
/
day076.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
int main() {
int matrix[20][20], in_row, in_col;
printf("Enter the no. of rows\n");
scanf("%d", &in_row);
printf("Enter the no. of columns\n");
scanf("%d", &in_col);
for(int i=0; i<in_row; i++){
for(int j=0; j<in_col; j++){
printf("insert the element for %d,%d\n", i, j);
scanf("%d", &matrix[i][j]);
}
}
printf("The matrix is\n");
for (int i=0; i<in_row; i++){
for (int j=0; j<in_col; j++){
if(j!=in_col-1)
printf("%d\t",matrix[i][j]);
else
printf("%d",matrix[i][j]);
}
printf("\n");
}
int start_row = 0, start_col = 0;
int end_row=in_row, end_col=in_col;
int store_value, temp;
while(start_row < end_row && start_col < end_col){
if(start_row + 1 == end_row || start_col + 1 == end_col)
break;
// store the first store_value....
store_value = matrix[start_row + 1][end_col - 1];
// Right to Left....
if(start_row < end_row){
for(int i = end_col-1; i >= start_col; i--){
temp = matrix[start_row][i];
matrix[start_row][i] = store_value;
store_value = temp;
}
}
start_row++;
// Top to Bottom....
for(int i = start_row; i < end_row; i++){
temp = matrix[i][start_col];
matrix[i][start_col] = store_value;
store_value = temp;
}
start_col++;
// Left to Right....
for(int i = start_col; i < end_col; i++){
temp = matrix[end_row-1][i];
matrix[end_row-1][i] = store_value;
store_value = temp;
}
end_row--;
// Bottom to Top....
if(start_col < end_col){
for(int i = end_row-1; i >= start_row; i--){
temp = matrix[i][end_col-1];
matrix[i][end_col-1] = store_value;
store_value = temp;
}
}
end_col--;
}
printf("Anti-Clockwise Rotation output is\n");
for(int i=0; i<in_row; i++){
for(int j=0; j<in_col; j++){
if(j!=in_col-1)
printf("%d\t",matrix[i][j]);
else
printf("%d",matrix[i][j]);
}
printf("\n");
}
return 0;
}