Question: Assignment 2 : Write a C program that generates a random walk across a ( 1 0 times 1 0 ) array.
Assignment : Write a C program that generates a "random walk" across a times 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 There are four possible values for the remainder and 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 generaterandomwalkchar walk;
and
void printarraychar walk;
generaterandomwalk returns if the walk is completed Z is reached It returns if the walk is blocked before reaching Z
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
