gift_random.h 随机赠品函数
void combination();
void random_fun(){
int random;
char gifta[20],giftb[20],giftc[20];
srand((unsigned)time(NULL));
random=rand()%121;
combination(); //调用组合数函数
switch_int_to_name(6,a[random],gifta);
switch_int_to_name(6,b[random],giftb);
switch_int_to_name(6,c[random],giftc);
printf("\n");
printf(" _________________________________________________\n");
printf("| You have reached the standard for getting a gift, |\n");
printf("| Please choose your gift: |\n");
printf("|_________________________________________________|\n");
printf("| 1 | 2 | 3 |\n");
printf("| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ | ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|\n");
printf("|%20s|%19s|%20s|\n",gifta,giftb,giftc);//a[random],b[random],c[random],这三个数对应着配件的数字,用一个转换函数
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n");
printf(" Your option:");
scanf("%d",&option_gift);
switch(option_gift){
case 1:
option_gift=switch_name_to_int(6,gifta);
break;
case 2:
option_gift=switch_name_to_int(6,giftb);
break;
case 3:
option_gift=switch_name_to_int(6,giftc);
}
system("pause");
}
/*
*组合数函数
*/
void combination(){
int array[N]={1,2,3,4,5,6,7,8,9,10};
int i,j,k;
int m=0,n=0;
for (i=0;i<=N-M;i++)
for(j=i+1;j<=N-M+1;j++)
for(k=j+1;k<=N-M+2;k++){
//printf("%d,%d,%d\n",array[i],array[j],array[k]);
a[m]=array[i];
b[m]=array[j];
c[m]=array[k];
m++;
}
}