Question: This assignment focuses on creating and manipulating selection control structures. The term combination in elementary algebra refers to one of the different ways a certain
This assignment focuses on creating and manipulating selection control structures.
The term combination in elementary algebra refers to one of the different ways a certain number of items can be selected from a list of items. For example, the combinations of four items a,b,c,d taken three at a time are abc, abd, acd, and bcd.
In other words, there are a total of four different combinations of four things "taken three at a time". In general, the number of combinations of n things taken k at a time is combinations = n! / ((n-k)!*k!), where the "!" is the symbol for factorial. The value of n! is n*(n-1)*(n-2)*...*1. For example, 4! = 4*3*2*1 = 24.
Factorial explained
Combinations explained
Calculate factorial using C programming 1 and 2
do while and while loop
check that the user enters an integer between 0 and 10 only
The assignment is to create a program to display the number of combinations where n and k are entered by the user.
STEPS:
1) Input 1.
Ask for n. Check for bounds (1 <= n && n <= 10). i) If the user entered an integer within (1 and 10), move on to getting the value for k ii) Else keep asking the user till they give a correct value which is an integer within 1 and 10. iii) Reject any input greater than 10 or less than 1 by displaying an error message and then asking the user to re-enter the input. Do this as many times that they enter incorrect input.
2) Input 2.
Ask for k. Check for bounds (1 <= k && k <= n). i. If the user entered an integer within (1 and k), move on to next step. ii. Else keep asking the user till they give a correct value which is an integer within 1 and n. iii. Reject any input greater than n or less than 1 by displaying an error message and then asking the user to re-enter the input. Do this as many times that they enter incorrect input.
3) Calculate n k.
4) Calculate factorial of n, k and n k.
5) Calculate the Combination by plugging in factorial of n / (factorial of k * factorial of n - k)
6) Output
Print 5, the number of combinations of n things taken k at a time. This is the output of your program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
