Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started