Question: Suppose, there are n objects and you are given the option to choose r objects from them. If the order of choice matters, it

Suppose, there are n objects and you are given the option to

 

Suppose, there are n objects and you are given the option to choose r objects from them. If the order of choice matters, it is called Permutation. Otherwise, it is known as Combination. Given the values of n and r, the number of permutations, P(n, r) and combinations, C(n,r) are determined using the following formula: n! P(n,r): (n-r)! n! C(n,r) r! (n r)! where,n! = 1x2 x3xx (n-1) xn Write a program that takes n and r as input and calculates the corresponding number of permutations and combinations. n and r should be non-negative integers and nr. If user gives illegal inputs, your code should print a proper error message. You are required to write a user- defined function to calculate the factorial. Call the function from main function to properly calculate the permutation and combination values. For this problem, recursion is not necessary.

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!