Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please show the complete code, including newlines and Spaces. please demo the result. Exercise Description This exercise is based on Exercise 9 on p179 and

Please show the complete code, including newlines and Spaces.

please demo the result.

image text in transcribedimage text in transcribedimage text in transcribed

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 labelled with the letters A throughz (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 .DE.ML.... ..WXYP Q... ..VUTSR... 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 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 You must have a Makefile that compiles your program into an executable called random_walk. Your

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What lessons in OD contracting does this case represent?

Answered: 1 week ago

Question

Does the code suggest how long data is kept and who has access?

Answered: 1 week ago