计算1到35的自然数中,从中任意选出7个数,共有几种组合? #include<iostream> #include<stdlib.h> #include<time.h> using namespace std; const int N=35; int b[7]; void quzhi() { int j=0; while(1) { for(int i=0;i<7;i++) b[i]=N*rand()/RAND_MAX; while(j<=5&&b[j]!=b[j+1]) j++; if(j==6) { cout<<"the radom 7 numbers:"; for(int i=0;i<7;i++) cout<<" "<<b[i]; return; } } } void showa(int array[],int x,int y) { for(int i=0;i<15;i++) if(array[i]!=0&&i!=y) cout<<" "<<array[i]; cout<<endl; } int main() { srand((unsigned)time(0)); quzhi(); cout<<endl<<"the different number array:"<<endl; int j=0,data; int a[15]; for(int i=0;i<15;i++) { if(i%2==0) a[i]=0; else { a[i]=b[j]; j++; } } int k; { for(int j=0;j<15;j++) { if(j%2==0) { for(k=0;k<7;k++) { a[j]=b[k]; showa(a,15,2*k+1); } a[j]=0; } } } return 0; }

评论