diff --git a/Algorithms/C++/Josephus_problem.cpp b/Algorithms/C++/Josephus_problem.cpp new file mode 100644 index 00000000..f49a963f --- /dev/null +++ b/Algorithms/C++/Josephus_problem.cpp @@ -0,0 +1,19 @@ +#include +#include +using namespace std; + +int josephus(int n, int k) +{ + if (n == 1) + { + return 1; + } + return (josephus(n - 1, k) + k - 1) % n + 1; +} + +int main() +{ + int numberOfpeople = 40, k = 7; + cout << "The chosen place is " << josephus(numberOfpeople, k); + return 0; +}