Permutations In Which N People Can Occupy R Seats In A Classroom | C++ Program

Permutations in which n people can occupy r seats in a classroom:-

C programming helps in identifying the r number of seats that can be occupied by n number of people. Such a program is known as the possible permutations. Here, We need to write a code to find all the possible permutations in which n people can occupy r number of seats in a classroom/theater.

N students are looking to find r seats in a classroom. Some of the seats are already occupied and only a few can accommodate in the classroom. The available seats are assumed as r and n number of people are looking to accommodate within the room.


Step 1: Start

Step 2: Ask the user to insert n number of people and the number of seats as r.

Step 3: Calculate permutation, p(n,r).

Step 4: Enter the program to calculate permutation P(n,r) = n! / (n-r)!

Step 5: Print the calculated result.

Step 6: Stop

C++ Code:-

#include <iostream>

using namespace std;

// Program to find the factorial of the number
int factorial (long int x)
long int fact=1,i;
return fact;
int main()
long int n,r,permutation,temp;
long int numerator, denominator;

// Insert the num of people

cout<<"\nEnter the number of persons : ";

// Insert the num of seats

cout<<"\nEnter the number of seats available : ";

// Base condition
// Swap n and r when n is less than r

if(n < r)
cout<<"\nNum of ways people can be seated : ";
Enter the number of persons : 3
Enter the number of seats available : 2
Num of ways people can be seated : 6