Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 labelled 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 BC 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 .. V UTSR. .. 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 (intn, int m, char walk[n] [m]); void print_array (int n, int m, char walk[n] [m])
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started