Explore

Edit

Edit

# Find all possible permutations in which 'n' people can occupy 'r' seats in a theater

Published on 10 Mar 2020

Program to find all possible permutations in which 'n' people can occupy 'r' seats in a theater is discussed here.

N friends are planning to go to a movie. One among them suggested few movies and all others started to discuss and finally they selected a movie. One among them quickly booked their tickets online, to their surprise they are unable to select their seats. All of them got confused. Then anyhow, decided to go to the movie. They rushed to reach the theater on time. Again they are surprised that no one was there in the theater. They are the only people about to watch the movie. There is 'r' number of seats in which, 'n' number persons should sit. In how many ways they can sit inside the theater?

Given the number of people 'n' and the number of seats 'r' as input. The task is to find the different number of ways in which 'n' number of people can be seated in those 'r' number of seats.

For example,

Input:

Number of people: 5

Number of Rows: 3

Output:

The total number of ways in which 'n' people can be seated in 'r' seats = 60.

Calculation:

P(n,r) =P(5,3)

=5! /(5?3)! = 5! / ( 5 ? 3 )!

= 120 / 2 = 60

## Algorithm to find all possible permutations in which 'n' people can occupy 'r' seats in a theater

• Input the number of people 'n' and the number of seats 'r' from the user.
• Calculate Permutation, p(n,r).
• P(n,r) = n! / (n - r)!
• Display the result.

Program to find all possible permutations in which n people can occupy r seats in a theater is given below.

C
C++
Java
Python 3

Output
Enter the number of seats available : 5
Enter the number of people : 3
Number of ways in which people can be seated : 60

Time complexity: O(n)

Recommended Programs