c语言试题,设计一个小迷宫。
# include & ltstdio.h & gt
作废打印(整数){
char a[n][n];
for(int I = 0;我& ltn;i++)
for(int j = 0;j & ltn;j++)
a[I][j]=“”;
int count = 0;
char c = ' A
int i = 0,j = 0,di = 0,DJ = 1;
while (1) {
if (a[i][j] == ' ') {
a[I][j]= c;
count++;
如果(c!= ' Z ')c++;
else c = ' A
}
if(count = = n * n)break;
if (a[i + di][j + dj]!= ' ' | | I+di & gt;= n | | j+DJ & gt;= n) {
int t = di
di = dj
DJ =-t;
}
I+= di;
j+= DJ;
}
for(int I = 0;我& ltn;i++) {
for(int j = 0;j & ltn;j++) {
printf("%c ",a[I][j]);
if(j & lt;n-1)printf(" ");
}
printf(" \ n ");
}
}
int main () {
int n;
scanf("%d ",& ampn);
for(int I = 0;我& ltn;i++) {
int x;
scanf("%d ",& ampx);
打印(x);
}
返回0;
}