Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide explanations for the code and portray the codes in an appropriate manner. thanks CODE IN C, ARRAY ONLY, BASED ON THE CODE BELOW

Please provide explanations for the code and portray the codes in an appropriate manner. thanks

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

CODE IN C, ARRAY ONLY, BASED ON THE CODE BELOW Background For this homework, you will work on a problem named "who gets the cake". Let's start with the introduction of this problem. Imagine that there is a piece of cake and several people want it. They decide who can have it by playing a game: They form a circle and choose an integer k greater than one. They count 1,2,3,,k. The k-th person is eliminated. They keep counting until only one person is left. This person who is left gets the cake. Please notice that there are different definitions of this problem. Your solution must follow the definition here. More precisely, this is how the method works: There are n people ( n is an integer), represented by n elements in an array. The elements are counted as 1,2,3,. When the value k is counted, this element is removed in future counting and the next element starts as 1 again. When reaching the end of the array, the counting wrap around to the beginning of the array (skipping the elements that have already been eliminated). Please notice that in C arrays, indexes always start at zero but in this problem counting starts at one. Both n and k have to be greater than one. It is possible that k is greater than n. Examples - The following is an example when the array has 6 elements (n is 6) and k is 3 . The eliminated elements in each round are mared by x. The elements eliminated earlier are marked by Y. The element of index 0 is left. - This is the second example. The array has 4 elements (n is 4) and k is 6 . This is an example where k is greater than n. The element of index 2 is left. Write the function in to print the index of the eliminated elements in order. In the first example (n=6,k=3), the output is 2 5 3 1 4 0 In the second example (n=4,k=6), the output is

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

T Sql Fundamentals

Authors: Itzik Ben Gan

4th Edition

0138102104, 978-0138102104

More Books

Students also viewed these Databases questions