Permutations to arrange N persons around a circular table - GeeksforGeeks

18 Jan, 2022
Given N, the number of persons. The task is to arrange N person around a circular table.Examples:  
Input: N = 4
Output: 6

Input: N = 5
Output: 24
 
Approach: It is the concept of Circular permutation i.e. there is no specific starting point in the arrangement, any element can be considered as the start of the arrangement. For N = 4, Arrangements will be: 
Below is the formula to find Circular permutations:  
Circular Permutations = (N - 1)!
Below is the implementation of above idea:  
C++
Java
Python 3
C#
PHP
Javascript
// C++ code to demonstrate Circular Permutation#include <bits/stdc++.h>using namespace std; // Function to find no. of permutationsint Circular(int n){     int Result = 1;     while (n > 0) {        Result = Result * n;        n--;    }     return Result;} // Driver Codeint main(){    int n = 4;     cout << Circular(n - 1);}
// Java code to demonstrate// Circular Permutationimport java.io.*; class GFG{// Function to find no.// of permutationsstatic int Circular(int n){     int Result = 1;     while (n > 0)    {        Result = Result * n;        n--;    }     return Result;} // Driver Codepublic static void main(String[] args){    int n = 4;         System.out.println(Circular(n - 1));}} // This code is contributed// by Naman_Garg
# Python 3 Program to demonstrate Circular Permutation  # Function to find no. of permutationsdef Circular(n) :    Result = 1     while n > 0 :        Result = Result * n        n -= 1     return Result     # Driver Codeif __name__ == "__main__" :    n = 4     # function calling    print(Circular(n-1)) # This code is contributed by ANKITRAI1
// C# code to demonstrate// Circular Permutationusing System;                      public class GFG { // Function to find no.// of permutationsstatic int Circular(int n){      int Result = 1;      while (n > 0)    {        Result = Result * n;        n--;    }      return Result;}  // Driver Codepublic static void Main(){    int n = 4;          Console.Write(Circular(n - 1));}}  /* This Java code is contributed by 29AjayKumar*/
<?php// PHP code to demonstrate Circular Permutation // Function to find no. of permutationsfunction Circular($n){    $Result = 1;     while ($n > 0)    {        $Result = $Result * $n;        $n--;    }     return $Result;} // Driver Code$n = 4; echo Circular($n - 1); // This code is contributed by mits?>
<script>// javascript code to demonstrate// Circular Permutation     // Function to find no.    // of permutations    function Circular(n)    {        var Result = 1;        while (n > 0)        {            Result = Result * n;            n--;        }         return Result;    }     // Driver Code    var n = 4;    document.write(Circular(n - 1)); // This code is contributed by Rajput-Ji</script>
6
 
ankthon
Naman_Garg
29AjayKumar
Mithun Kumar
Rajput-Ji
varshagumber28
math
permutation
Permutation and Combination
C++ Programs
Mathematical
Mathematical
permutation
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Passing a function as a parameter in C++
Const keyword in C++
Program to implement Singly Linked List in C++ using class
cout in C++
Handling the Divide by Zero Exception in C++
Program for Fibonacci numbers
C++ Data Types
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
Coin Change | DP-7