6. The combination of n items taken r at a time, denoted C, and pronounced \"n c
ID: 3741582 • Letter: 6
Question
6. The combination of n items taken r at a time, denoted C, and pronounced "n choose r" is the number of ways in which you can choose a subset of r items from a set of n items: 1.2 3 . 1r For example, if you have a standard 52 card poker deck (assuming no jokers and nothing wild), the number of possible 5 card poker hands is "52 choose 5:" 52 51 - 50 49 483 311,875,200 = 2,598,960 1 2 3 4.5 120 Write a C program that takes as its input n, the total number of items available (for example, 52 cards in a deck), and r, the size of the subgroup to be created (for example, 5 cards in a poker hand), and outputs ,C. (For this homework question, you do not need to include comments if you don't want, and you may use numeric literal constants in the body of the program.)Explanation / Answer
Solution:
code:
#include <stdio.h>
long double factorial( long double p)
{
long double facto = 1;
long double i;
for( i = 1; i<= p; i++)
facto = facto * i;
return( facto);
}
long double ncr( long double n, long double r)
{
return( factorial( n) / (factorial( r) * factorial(n- r) ) ) ;
}
int main()
{
long double n , r;
printf(" Enter value of n & r ");
scanf("%llf %llf",&n , &r);
printf( " %llf C: %llf is %llf ", n,r,ncr( n , r));
return 0;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.