Dog leaves his lamppost on summer evenings and staggers randomly either two steps in the direction toward home or one step in the opposite direction. After taking these steps, the dog again staggers randomly two steps toward home or one step backward and does this again and again. If the pet reaches a total distance of 10 steps from the lamppost in the direction toward home, you find him and take him home. If the dog arrives back at the lamppost before reaching 10 steps in the direction toward home, he lies down and spend the night at the foot of the lamppost. Write a C program that stimulates 500 summer evenings, and calculate and print the percentage of the time your pet sleeps at home for these evenings. Accumulate the distance the dog has reached toward your home. If the distance reaches 10, stop the loop and increment the home count. If the distance reaches 0 before it reaches 10, stop the loop but do not increment the home count. Repeat this loop 500 times and find the ratio of (home count)/500.0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.