Seating arrangement of N boys sitting around a round table such that two particular boys sit together - GeeksforGeeks

31 Mar, 2021
There are N boys which are to be seated around a round table. The task is to find the number of ways in which N boys can sit around a round table such that two particular boys sit together.Examples:  
Input: N = 5 Output: 48 2 boy can be arranged in 2! ways and other boys can be arranged in (5 – 1)! (1 is subtracted because the previously selected two boys will be considered as a single boy now) So, total ways are 2! * 4! = 48.Input: N = 9 Output: 80640  
 
Approach:  
First, 2 boys can be arranged in 2! ways.
No. of ways to arrange remaining boys and the previous two boy pair is (n – 1)!.
So, Total ways = 2! * (n – 1)!.
Below is the implementation of the above approach:  
C++
Java
Python3
C#
Javascript
// C++ implementation of the approach#include <bits/stdc++.h>using namespace std; // Function to return the total count of waysint Total_Ways(int n){     // Find (n - 1) factorial    int fac = 1;    for (int i = 2; i <= n - 1; i++) {        fac = fac * i;    }     // Return (n - 1)! * 2!    return (fac * 2);} // Driver codeint main(){    int n = 5;     cout << Total_Ways(n);     return 0;}
// Java implementation of the approachimport java.io.*; class GFG{     // Function to return the total count of waysstatic int Total_Ways(int n){     // Find (n - 1) factorial    int fac = 1;    for (int i = 2; i <= n - 1; i++)    {        fac = fac * i;    }     // Return (n - 1)! * 2!    return (fac * 2);} // Driver codepublic static void main (String[] args){     int n = 5;     System.out.println (Total_Ways(n));}} // This code is contributed by Tushil.
# Python3 implementation of the approach # Function to return the total count of waysdef Total_Ways(n) :     # Find (n - 1) factorial    fac = 1;    for i in range(2, n) :        fac = fac * i;             # Return (n - 1)! * 2!    return (fac * 2);  # Driver codeif __name__ == "__main__" :     n = 5;     print(Total_Ways(n)); # This code is contributed by AnkitRai01
// C# implementation of the approachusing System; class GFG{ // Function to return the total count of waysstatic int Total_Ways(int n){     // Find (n - 1) factorial    int fac = 1;    for (int i = 2; i <= n - 1; i++)    {        fac = fac * i;    }     // Return (n - 1)! * 2!    return (fac * 2);} // Driver codestatic public void Main (){    int n = 5;     Console.Write(Total_Ways(n));}} // This code is contributed by ajit..
<script>// javascript implementation of the approach     // Function to return the total count of ways    function Total_Ways(n)    {         // Find (n - 1) factorial        var fac = 1;        for (i = 2; i <= n - 1; i++)        {            fac = fac * i;        }         // Return (n - 1)! * 2!        return (fac * 2);    }     // Driver code        var n = 5;        document.write(Total_Ways(n)); // This code is contributed by aashish1995</script>
48
 
ankthon
jit_t
aashish1995
Permutation and Combination
Mathematical
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Merge two sorted arrays
Modulo Operator (%) in C/C++ with Examples
Prime Numbers
Program to find GCD or HCF of two numbers
Sieve of Eratosthenes
Print all possible combinations of r elements in a given array of size n
Operators in C / C++
The Knight's tour problem | Backtracking-1
Program for factorial of a number
Program for Decimal to Binary Conversion