Question: Write a function that calculates permutations. Permutations help us figure how many unique possibilities exist when you take for example a 4 digit pin code

Write a function that calculates permutations. Permutations help us figure how many unique possibilities exist when you take for example a 4 digit pin code based on digits from 0-9. In permutations, the order does matter. (this is the opposite of combinations).
We typically define this be describing it as \( n \) objects taken \( r \) at a time. In the above example, our n objects are the digits Zero through Nine... so \(\mathrm{n}=10\). And since we have 4 digits in the pin code, \( r=4\).
The formula to calculate the permutations is given as:
\[
P(n, r)=\frac{n!}{(n-r)!}
\]
Write a function that takes the input parameters and computes the permutations. Please execute this script without using MATLAB's built-in factorial. In other words, you will most likely need to use for loop(s) for this calculation. (Hint, you could check your code by using MATLAB's built-in for factorial !- pun intended)
Be sure to develop a structure plan or psuedo code that you write before actually writing the commands.
Write a function that calculates permutations.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!