3
Answers

How to permutation and combination?

Ken H

Ken H

12y
2.6k
1
hi,
   i have 8 digital,now I want to know a choice 5 combination how many kinds of.

Code fragment:

#include <cstdio>
void main()
{
 int ResultNum[8]={1,8,9,10,11,14,17,20},i,j=0,k=0;
 for (i=0;i<8;i++)
 {  
  for (j=i+1;j<8;j++)
  {
   
      if(k<=5)
   {
         // how to do?       
      printf("\n");
       k++;
   }
   else if (k>=5) k=0;
  }
  
 }
}


Below is the result of simulation:
NO.1: 
        1,8,9,10,11
NO.2:
         1,8,9,10,14
NO.3:
          1,8,9,10,17
NO.4:
          1,8,9,10,20
NO.5:
           1,8,9,11,14
NO.6:
           1,8,9,11,17
NO.7:
            1,8,9,11,20
NO.8:
           1,8,10,11,14
......
......
......


thanks.

Answers (3)