Josephus Problem using Circular Doubly Linked List. (Your program should print the remaining people in each iteration). also show output.
#include <stdio.h>
int josephus(int num, int x)
{
if (num == 1)
return 1;
else
return (josephus(num - 1, x) + x - 1) % num + 1;
}
int main()
{
int num = 25;
int x = 3;
printf("The place chosen is: %d", josephus(num, x));
return 0;
}
Comments
Leave a comment