Question: Write a C program to simulate the random walk of a creature on an X-Y coordinate plane. The creature begins at the origin (coordinates (0,0)).

Write a C program to simulate the random walk of a creature on an X-Y coordinate plane. The creature begins at the origin (coordinates (0,0)). Each time step it moves 1 unit distance north with probability 0.30, south (probability 0.25), east (probability 0.20), west (probability 0.15), or remains in the same location (probability 0.1). For example, if the creature is initially at the origin (coordinates (0,0)) and decides to move south, it moves to coordinate position (0,-1) that time step. The decision of what to do in the current time step does not depend on decisions in previous time steps.

Write a program that simulates the movement of the creature. Your output should be written into a file called Position. Every time unit it should write a new line into the file indicating the X and Y coordinate of the creature, e.g., to look something like this:

0 0

0 -1

1 -1

...

Run your program for 100 time units, and turn in the source code for your program as well as the Position file your program produced. You may use the rand function from the C standard library in your program. Write your program to minimize the amount of storage needed and the amount of computation required. Be sure to document your code.

Now write a new program that reads the Position file produced above, and writes into a new file called Distance the distance of the creature from the origin (coordinate position (0,0)) at each time step. Y ou may wish to use the sqrt function defined in math.h for this problem (the prototype is shown below):

double sqrt (double x); Run the program for 100 time steps. Turn in the source code and Distance file produced by

your program.

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!