Home > Back-end >  C test work, don't beg, teach
C test work, don't beg, teach

Time:11-03

. Write a program to calculate the combination of the group number, pulling m out of n elements [1] [5] to m elements into a sequence of five groups so the combination of number, its computation formula is n!/m [1]. *... * m [5].

CodePudding user response:

Feel this formula cannot be directly calculated by program, at least n! Is a large number, 100! Can't say computer int, need to be simplified formula?

CodePudding user response:

Direct arrangement number P (n, r) calculation is not ok?
P (n, r)=n (n - 1) (n - 2)... (n - r + 1)
You this is p (n, 5)=n (n - 1) (n - 2)... 5 + (n - 1)
Int n;
Cin> n;
Int ret=1;
For (int r=1; i<=5; I++)
{
Ret *=n - (I) + 1;
}//ret result is

CodePudding user response:

But n is too large, ret will overflow, but as a homework, your teacher will not consider these,