Count of distinct permutations of every possible length of given string | C ++ implementation of the above approach ; Function to find the factorial of a number ; Loop to find the factorial of the given number ; Function to find the number of permutations possible for a given string ; Function to find the total number of combinations possible ; Driver Code
#include <bits/stdc++.h> NEW_LINE #include <iostream> NEW_LINE using namespace std ; int fact ( int a ) { int i , f = 1 ; for ( i = 2 ; i <= a ; i ++ ) f = f * i ; return f ; } int permute ( int n , int r ) { int ans = 0 ; ans = ( fact ( n ) / fact ( n - r ) ) ; return ans ; } int findPermutations ( int n ) { int sum = 0 , P ; for ( int r = 1 ; r <= n ; r ++ ) { P = permute ( n , r ) ; sum = sum + P ; } return sum ; } int main ( ) { string str = " xz " ; int result , n ; n = str . length ( ) ; cout << findPermutations ( n ) ; return 0 ; }