Question: Please write this program in C and only using arrays, no linked lists. The starter code is provided in the last photo, please add onto

 Please write this program in C and only using arrays, nolinked lists. The starter code is provided in the last photo, pleaseadd onto that. Please also include detailed explanations. WIll upvote for goodanswers, Imagine that there is a piece of cake and several peoplewant 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 restart from 1and count to k again to eliminate the next person whose numberis k. They keep counting until only one person is left. This

Please write this program in C and only using arrays, no linked lists. The starter code is provided in the last photo, please add onto that. Please also include detailed explanations. WIll upvote for good answers,

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 restart from 1 and count to k again to eliminate the next person whose number is k. They keep counting until only one person is left. This person 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, represented by are 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. The following is an example when the array has 6 ( n is 6 ) elements and k is 3 . The eliminated elements in each round are mared by X. The elements eliminated earlier are marked by Y. Go to the beginning. Since index 2 has already been eliminated, it is skipped. Index 3 is eliminated this time. Index 5 has already been eliminated and it is skipped. Index 1 is eliminated this time. Index 4 is eliminated this time. The element of index 0 is left. This is another example. The array has 6 elements and k is 4 . \begin{tabular}{|l|c|c|c|c|c|c|} \hline array index & 0 & 1 & 2 & 3 & 4 & 5 \\ \hline count & 3 & X & 1 & Y & 2 & 3 \\ \hline array index & 0 & 1 & 2 & 3 & 4 & 5 \\ \hline count & X & Y & 1 & Y & 2 & 3 \\ \hline \end{tabular} \begin{tabular}{|l|c|c|c|c|c|c|} \hline array index & 0 & 1 & 2 & 3 & 4 & 5 \\ \hline count & Y & Y & X & Y & 1 & 2 \\ \hline \end{tabular} \begin{tabular}{|l|c|c|c|c|c|c|} \hline array index & 0 & 1 & 2 & 3 & 4 & 5 \\ \hline count & Y & Y & Y & Y & 3 & X \\ \hline \end{tabular} The element of index 4 is left. This is the third example. The array has 25 elements and k is 7 . This is the third example. The array has 25 elements and k is 7. The element of index 14 is left. The table uses X and Y for clarity. Your program should use only X. Write the function and print the index of the eliminated elements. In the first example, the output is In the second example, the output is In the third example, the output is The function is called eliminate, not select because select is a C function for communication. If you want to know the definition of the select function, search Linux manual select

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!