Question: Computer Science - With program C Exercise 1. (50 points) Circular Random Walk In this problem we will write a program to simulate a circular

Computer Science - With program C Computer Science - With program C Exercise 1. (50 points) Circular Random

Exercise 1. (50 points) Circular Random Walk In this problem we will write a program to simulate a circular random walk. Imagine we have the following numbers 0,1,2,...,k -2, k - 1 evenly spaced on a circle in clockwise direction just like a clock. A random walker starts from 0 and randomly walks along the circle. With probability 0.5, he walks clockwise to the next number; with probability 0.5, he walks counter-clockwise to the next number. For example, at 0, he can walk to 1 in the clockwise direction, or walk to 9 in the counter-clockwise direction We will implement a function circular random walk in circular-random.c. This function takes a single parameter k as described above, and returns the number of steps the walker takes until it returns to 0 In the main() function, a user is allowed to enter a value for k, and the program will run the simulation 1,000,000 times and report the average and the maximum steps for the walker to return 0 You should know it if your code is correct because the results are very special and interesting Exercise 2. (50 points) Modular Power Calculator In this problem, we will write a program that calculates be mod m for given integers b, e and m. We assume that b > 0, e > 0, and m > 1 and all of them are less than 231-1. Here mod is the Modulus operator. In our implementation, we will leverage the following fact a x b mod m- [a modm) x (b mod m mod m Consider the following example where b = 5, e = 3, and m = 7, We need to calculate 53 mod 7. By applying the above fact, we have the following 53 mod 7 = 52 5 mod 7 (52 mod 7) x (5 mod 7)] mod 7 5 mod 7) x (5 mod 7) mod 7 x (5 mod 7)) mod 7 In general, we have the following recursion be mod m = (be-1 mod m) (b mod m)| mod m Write two functions - one will solve the problem using for loop and the other one using a recursive function Sample output. ./modeexpo Enter b:5 Enter e:3 Enter m:7 Result using recursion:6 Result using loop:6

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!