Permutations of n things taken r at a time with k things together | CPP program to find the number of permutations of n different things taken r at a time with k things grouped together ; Function to find factorial of a number ; Function to calculate p ( n , r ) ; Function to find the number of permutations of n different things taken r at a time with k things grouped together ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int factorial ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } int npr ( int n , int r ) { int pnr = factorial ( n ) / factorial ( n - r ) ; return pnr ; } int countPermutations ( int n , int r , int k ) { return factorial ( k ) * ( r - k + 1 ) * npr ( n - k , r - k ) ; } int main ( ) { int n = 8 ; int r = 5 ; int k = 2 ; cout << countPermutations ( n , r , k ) ; return 0 ; }