#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 21
void display(int x[][SIZE]);
int main()
{
srand((unsigned)time(NULL));
int walk[SIZE][SIZE] = { 0 };
int i=0, n,init,number,a=11,b=11;
while (i < 11)
{
walk[a][b] = 1;
number = rand() % 8;
switch (number)
{
case 0:
a += 1;
break;
case 1:
a += 1;
b += 1;
break;
case 2:
b += 1;
break;
case 3:
a -= 1;
b += 1;
break;
case 4:
a -= 1;
break;
case 5:
a -= 1;
b -= 1;
break;
case 6:
b -= 1;
break;
case 7:
a += 1;
b -= 1;
break;
}
i++;
}
display(walk);
}
void display(int x[][SIZE])
{
int i, n;
for (i = 0; i < SIZE; i++)
{
for (n = 0; n < SIZE; n++)
{
if (x[i][n] == 1)
printf("*");
else
printf(".");
}
printf("\n");
}
}
댓글