Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that generates a “random walk” across a 10 x 10 array. The array

ID: 3640004 • Letter: W

Question

Write a program that generates a “random walk” across a 10 x 10 array. The array will contain character (all ‘.’ Initially). The program must randomly “walk” from element to element, always going up, down, left, or right by one element. Z, in the order visited. Here’s an example of the desired output:

A . . . . . . . . .

B C D . . . . . . .

. F E . . . . . . .

H G . . . . . . . .

I . . . . . . . . .

J . . . . . . . . .

K . . R S T U V Y .

L M P Q . . . W X .

. N O . . . . . . .

. . . . . . . . . .

Hint: Use the srand and rand functions to generate random numbers. After moving possible values for the remainder—0, 1, 2, and 3—indicating the direction of the next move. Before performing a move, check that (a) it won’t go outside the array, and (b) it doesn’t take us to element that already has a letter assigned. If either condition is violated, try moving in another direction. If all four directions are blocked, the program must terminate. Here’s an example of premature termination:

A B G H I . . . . .

. C F . J K . . . .

. D E . M L . . . .

. . . . N O . . . .

. . W X Y P Q . . .

. . V U T S R . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .


Explanation / Answer

# include # include # define TRUE 1 # define FALSE 0 time_t seed; main() { seed = time(NULL); srand(seed); char grid[10][10]; char currentchar = 'A'; int i, j, r, loop, row, col; for (i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote