Write a function that returns the number of permutations of the n objects taken k at a time.
The function is int permute(int n; int k).
Example:
Consider the set of digits 1,2,3, the different permutations of two digits are 1,2,2,1,1,3,2,3,3,2.
Function makes use of: n!/(n-k)!
I think I have to make a for loop to compute n! and then I'm guessing another for loop for (n-k)! and then divide these two.
The code that I have so far is:
I'm not sure if this code is correct though or if there is an easier way to do it. Please help me out.Code:int permute(int n; int k) { int factn; int factk; if(n == 0) { factn = 1; } else { factn = n * permute(n - 1); factk = k * permute(k – 1); } return permute(factn / factk); }