Question: Exercise Description This exercise is based on Exercise 9 on p179 and Exercise 3 on p217 Write a program called random_walk.c that generates a random

 Exercise Description This exercise is based on Exercise 9 on p179and Exercise 3 on p217 Write a program called random_walk.c that generatesa "random walk" across any 2-D array, starting at the top left

Exercise Description This exercise is based on Exercise 9 on p179 and Exercise 3 on p217 Write a program called random_walk.c that generates a "random walk" across any 2-D array, starting at the top left corner. 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 the letters A through Z (i.e., do not walk past Z), in the order visited. Hint: Use srand and rand functions to generate random numbers. Remember that you want to generate a number between 0 - 3, which can correspond to each possible direction of the next move. Before performing a move, check (1) that it won't go outside the array, and (2) that it doesn't visit an element that already has a letter assigned. If there is no position it can visit withouth violating these conditions, the program must terminate and indicate the last letter it was able to write. Here are three samples of what a program run might look like (print a dot for unvisited elements): Enter number of rows: 3 Enter number of columns: 2 Walked until letter D A D B C Enter number of rows 10 Enter number of columns: 10 Walked until letter Z Enter number of rows: 10 Enter number of columns: 10 Walked until letter Y ABGH .CF.JK Your program must contain the following functions (note that here, you are making use of C99's variable length array parameters feature) void generate_random_walk (int n, int m, char walk[n] [m]); void print_array (int n, int m, char walk[n] [m]); After reading all necessary input from the user and declaring the array,the main function of your program must call generate_random walk . generate_random_walk must initialize the array to contain '" characters, and then replaces the characters with the letters from A to Z as it does its random walk through the array. main then calls print_array to display the array on the screen. Note: you need to think about the right place to print the statement indicating the last letter reached. You cannot change the function prototypes You must have a Makefile that compiles your program into an executable called Makefile must have the clean target. random walk . Your

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 Databases Questions!