Question: Assignment 2 : Write a C program that generates a random walk across a ( 1 0 times 1 0 ) array.

Assignment 2: Write a C program that generates a "random walk" across a \(10\times 10\) array. The array will contain characters (all '.' initially). The program must randomly "walk" from element to element, always going up, down, left, or right by one element. The elements visited by the program will be labeled with letters A through Z, in the order visited. Here's an example of the desired output:
Hint: Use the srand () and rand () functions in the standard library to generate random numbers. You can use the time () function to generate a seed based on time. After generating a number, look at its remainder modulo 4. There are four 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 an 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:
In your C program include the following functions:
int generate_random_walk(char walk[10][10]);
and
void print_array(char walk[10][10]);
generate_random_walk() returns 0 if the walk is completed ( Z is reached). It returns 1 if the walk is blocked before reaching Z .
Assignment 2 : Write a C program that generates 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!