The expression C(n,r) denotes the number of r -element subsets of an n -element
ID: 3612817 • Letter: T
Question
The expression C(n,r) denotes the number ofr-element subsets of an n-element set. Thisis a combinatorial function pronounced as “n chooser”. For example, given a set of 4 colors
{ red, blue, green, yellow }, how many distinct sets of 2 colorscan we make? (Note: the sets { red, blue } and { blue,red } are not-distinct.) C(4,2)=6 , hencethere are six distinct subsets of 2 elements – { red, blue },{ red, green }, { red, yellow }, { blue, green }, { blue, yellow },and { green, yellow }. The value of C(n,r) is given bythe formula
Write a program in C that computes C(n,r) using the followingcomponent functions
i. main(): prompts the user for two numbersstoring them in variables n andr respectively; and then prints theresult after C(n,r) is computed.
ii. check(): compares r and n. If r >n or if r orn are negative, check()invokes the function err_msg() which prints anerror message. The program will then terminate.
iii. comb(): computesC(n,r) .
iv. fact(): computes afactorial.
Explanation / Answer
please rate - thanks #include #include bool check(int,int); void err_msg(); int comb(int, int); double fact(int); int main() {int c,r,n; bool valid; printf("How many elements in the set? "); scanf("%d",&n); printf("How large is the subset? "); scanf("%d",&r); if(check(n,r)) {c=comb(n,r); printf("There are %dC%d = %d ",n,r,c); } getch(); return 0; } bool check(int n, int r) {if(r>n||rRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.