Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago