Question: adjust this c program #include #include / * srand ( ) , rand ( ) * / #include / * time ( ) * /

adjust this c program
#include
#include /* srand(), rand()*/
#include /* time()*/
int main(void){
char letter ='A',
grid[10][10]={0};
int i =0,
j =0,
up =0,/* directions are essentially bools, written as ints to */
down =0,/* conform with C89 standard. */
left =0,
right =0,
move =0;
srand((unsigned) time(NULL));
grid[i][j]= letter++;
while (letter <='Z'){
up = down = left = right = move =0;
if (j +1<10 && grid[i][j +1]==0)
up =1;
if (j -1>=0 && grid[i][j -1]==0)
down =1;
if (i +1<10 && grid[i +1][j]==0)
right =1;
if (i -1>=0 && grid[i -1][j]==0)
left =1;
if (up + down + left + right ==0)
break;
move = rand()%4;
/* Intentional fallthrough if direction fails */
switch(move){
case 0:
if (up){
grid[i][++j]= letter++;
break;
}
case 1:
if (down){
grid[i][--j]= letter++;
break;
}
case 2:
if (right){
grid[++i][j]= letter++;
break;
}
case 3:
if (left){
grid[--i][j]= letter++;
break;
}
default:
break;
}
}
for (i =0; i <10; i++){
for (j =0; j <10; j++){
if (grid[i][j]==0)
grid[i][j]='.';
printf("%c ", grid[i][j]);
}
printf("
");
}
return 0;
}
Rather than stopping at 'Z', adjust the program so it continues until the path is blocked. After 'Z', the letters should start over again at 'A'.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!