Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need this in c programming assignment is given and also code is given you just have to code the lines where it says TODO

I need this in c programming

assignment is given and also code is given you just have to

code the lines where it says TODO here

please edit the code that i have given and please send me screenshot of the output as well

ITs a single assignment so please do answer both parts

image text in transcribed

image text in transcribed

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 .. 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 mod m) 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 mod7 52 5 mod 7 (52 mod 7) x (5 mod 7)] mod 7 {(5 mod 7) (5 mod 7) mod 7]x(5 mod 7)) mod 7 In general, we have the following recursion be mod m = [(F-1 mod m) x (b mod m)) mod m Write two functions one will solve the problem using for loop and the other one using a recursive functiorn Sample output >./modeexpo Enter b:5 Enter e:3 Enter m:7 Result using recursion:6 Result using loop:6 untitledhappy.c include 2 #include 3 #include 4 5 int next_number (int n) //TODO 8 9 10 int happy (int n) 12 / /TODO 14 int main() 16 17 18 19 20 int i; for (i-1; i

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

Question What is the advantage of a voluntary DBO plan?

Answered: 1 week ago