Seating arrangement of n boys and girls alternatively around a round table

There are n boys and n girls are to be seated around a round table, in a circle. The task is to find number of ways in which n boys and n girls can sit alternatively aound a round table. Given n<10

**Examples:**

Input: n = 5 Output: 2880 Input: n = 1 Output: 1

**Approach:**

- First find the total number of ways in which boys can be arrange on round table.

No. of ways to arrange boys on table =**(n-1)!** - After making boys arrangement, now make arrangement for girls. As after seating boys there are n space available between them. So there are n position and n number of girls. So total number of arrangement in which girls sit between boys are
**n!**. - Therefore Total number of ways = (number of arrangement of boys) * (number of ways to sit girl among boys) =
**(n-1)! * (n!)**

Below is the implementation of the above approach:

## C++

`// C++ program to find number of ways in which ` `// n boys and n girls can sit alternatively ` `// sound a round table. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `#define ll long int ` ` ` `int` `main() ` `{ ` ` ` ` ` `// Get n ` ` ` `ll n = 5; ` ` ` ` ` `// find fac1 = (n-1)! ` ` ` `ll fac1 = 1; ` ` ` `for` `(` `int` `i = 2; i <= n - 1; i++) ` ` ` `fac1 = fac1 * i; ` ` ` ` ` `// Find fac2 = n! ` ` ` `ll fac2 = fac1 * n; ` ` ` ` ` `// Find total number of ways ` ` ` `ll totalWays = fac1 * fac2; ` ` ` ` ` `// Print the total number of ways ` ` ` `cout << totalWays << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find number of ways ` `// in which n boys and n girls can sit ` `// alternatively sound a round table. ` `import` `java .io.*; ` ` ` `class` `GFG ` `{ ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` ` ` `// Get n ` ` ` `long` `n = ` `5` `; ` ` ` ` ` `// find fac1 = (n-1)! ` ` ` `long` `fac1 = ` `1` `; ` ` ` `for` `(` `int` `i = ` `2` `; i <= n - ` `1` `; i++) ` ` ` `fac1 = fac1 * i; ` ` ` ` ` `// Find fac2 = n! ` ` ` `long` `fac2 = fac1 * n; ` ` ` ` ` `// Find total number of ways ` ` ` `long` `totalWays = fac1 * fac2; ` ` ` ` ` `// Print the total number of ways ` ` ` `System.out.println(totalWays); ` `} ` `} ` ` ` `// This code is contributed ` `// by anuj_67.. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find number ` `# of ways in which n boys and n ` `# girls can sit alternatively ` `# sound a round table. ` ` ` `# Get n ` `n ` `=` `5` ` ` `# find fac1 = (n-1)! ` `fac1 ` `=` `1` `for` `i ` `in` `range` `(` `2` `, n): ` ` ` `fac1 ` `=` `fac1 ` `*` `i ` ` ` `# Find fac2 = n! ` `fac2 ` `=` `fac1 ` `*` `n ` ` ` `# Find total number of ways ` `totalWays ` `=` `fac1 ` `*` `fac2 ` ` ` `# Print the total number of ways ` `print` `(totalWays) ` ` ` `# This code is contributed ` `# by sahilshelangia ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find number of ways ` `// in which n boys and n girls can sit ` `// alternatively sound a round table. ` `using` `System; ` ` ` `class` `GFG ` `{ ` `public` `static` `void` `Main() ` `{ ` ` ` ` ` `// Get n ` ` ` `long` `n = 5; ` ` ` ` ` `// find fac1 = (n-1)! ` ` ` `long` `fac1 = 1; ` ` ` `for` `(` `int` `i = 2; i <= n - 1; i++) ` ` ` `fac1 = fac1 * i; ` ` ` ` ` `// Find fac2 = n! ` ` ` `long` `fac2 = fac1 * n; ` ` ` ` ` `// Find total number of ways ` ` ` `long` `totalWays = fac1 * fac2; ` ` ` ` ` `// Print the total number of ways ` ` ` `Console.WriteLine(totalWays); ` `} ` `} ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find number of ` `// ways in which n boys and n ` `// girls can sit alternatively ` `// sound a round table. ` ` ` `// Driver Code ` ` ` `// Get n ` `$n` `= 5; ` ` ` `// find fac1 = (n-1)! ` `$fac1` `= 1; ` `for` `(` `$i` `= 2; ` `$i` `<= ` `$n` `- 1; ` `$i` `++) ` ` ` `$fac1` `= ` `$fac1` `* ` `$i` `; ` ` ` `// Find fac2 = n! ` `$fac2` `= ` `$fac1` `* ` `$n` `; ` ` ` `// Find total number of ways ` `$totalWays` `= ` `$fac1` `* ` `$fac2` `; ` ` ` `// Print the total number of ways ` `echo` `$totalWays` `. ` `"\n"` `; ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` |

*chevron_right*

*filter_none*

**Output:**

2880

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.