Here is the code for you:
//Josephus Problem
#include <stdio.h>
#include <stdlib.h>
int main()
{ int i, N, M;
printf("How many people are in the circle? ");
scanf("%i", &N);
M = 2;
int count = N;
int array[N];
for(int i = 0; i < N; i++)
array[i] = i+1;
int current = 0;
int temp = 0;
while(count != 1)
{
if(array[current] != 0)
temp++;
current++;
if(current == N)
current = 0;
if(temp >= M-1 && array[current] !=
0)
{
temp = 0;
array[current] =
0;
count--;
}
}
for(int i = 0; i < N; i++)
if(array[i] != 0)
{
printf("The spot %i is safe.\n",
array[i]);
break;
}
}
And the output screenshot is:
In computer science and mathematics, the Josephus problem (or Josephus permutation) is a theoretical prob- lem...
The Josephus Problem People are standing in a circle (Links to an external site.)Links to an external site. waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only...
Need different C code then what has been posted here Problem In this assignment, you have to simulate the Josephus problem. There are n number of prisoners standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller...
Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...