Home > Back-end >  C language implementation mathematical combination problems
C language implementation mathematical combination problems

Time:03-30

combination (combination)
One of the important concepts of mathematics, from n every time out m different elements in different elements (0 m, n) or less or less, regardless of the synthesis of a set of order, called from the selection of n elements, not repeatedly m a combination of elements, the combination of all that is called by the total number of combinations of,
The arithmetic idea for the
Is to remove the number from the N M number, each take a number, from the rest of the number of N - 1 take the rest of the number of M - 1, when to finish the output line,

code
 # include & lt; Stdio. H> 

# define MAXIN 10

Int a [MAXIN]={0};//initialize array
Int counts=0;
//implementation function
Void Combination (int n, int m)
{//m number out of the n
int i,j;
If (m<=0)
{//when m=0; Exit the loop
For (j=1; J<=counts; J++)
Printf (" % d ", a [j]);
printf("\n");
return;
}
For (I=n; I>=m; I -)
{
A [m]=I;
Combination (I - 1, m - 1);//from the rest of the number of n - 1 m - number 1
}
}

Int main ()
{
int n, m;
The scanf (" % d % d ", & amp; N, & amp; M);
Counts=m;
Combination (n, m);
return 0;
}


Results the



CodePudding user response:

  • Related