-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnightfall.c
101 lines (68 loc) · 1.4 KB
/
Knightfall.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
93
94
95
96
97
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
void scanArray(int A[3][3]);
void rotateCounterClockwise(int V[3][3]);
void rotateClockwise(int V[3][3]);
int main(){
int Array[3][3]={},i,j;
char str;
scanArray(Array);
//printf("scanned values: %d %d %d",Array[3][0],Array[3][1],Array[3][2]);
printf("Please enter the rotate direction l-CounterClockwise r-Clockwise e-exit.:\n");
str=getchar();
str=getchar();
//printf("%c",str);
if(str == 'r'){
rotateClockwise(Array);
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%c",Array[i][j]);
}
printf("\n");
}
}
else if(str == 'l'){
rotateCounterClockwise(Array);
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%c",Array[i][j]);
}
printf("\n");
}
}
else{printf("error");}
return 0;
}
void scanArray(int A[3][3]){
char ch;
int i,j;
printf("Please enter the array in a one line without spaces:.\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
ch=getchar();
if(isalpha(ch)){
A[i][j]=ch;
}
}
}
return;
}
void rotateClockwise(int V[3][3]){
int col,row,i,j;
for(i=0,row=0;i<3 && row<3;i++,row++){
for(j=0,col=2;j<3 && col>=0;j++,col--){
V[i][j]=V[col][row];
}
}
return;
}
void rotateCounterClockwise(int V[3][3]){
int col,row,i,j;
for(i=0,row=2;i<3 && row>=0;i++,row--){
for(j=0,col=2;j<3 && col>=0;j++,col--){
V[i][j]=V[col][row];
}
}
return;
}