代码如下。。
#include <stdio.h>
#include <time.h>
int main()
{
int i;// the number of the array;
int key;
int dcbr[34];
int dcbb[17];
//set the value;
for (i = 1; i < 34; i++)
dcbr[i] = i;
for (i = 1; i < 17; i++)
dcbb[i] = i;
srand((unsigned)time(NULL));
//reb ball;
for(i = 1; i < 7;i++){
printf("第 %d 个红球:",i);
key = (rand()%(34-i)) + 1;
printf("%d\n",dcbr[key]);
for (;key <(34-i);key++)
dcbr[key] = dcbr[key+1];
dcbr[34-i] = 0;
}
//blue ball
printf("蓝球:");
key = rand()%16 + 1;
printf("%d\n",dcbb[key]);
return 0;
}
#include <stdio.h>
#include <time.h>
int main()
{
int i;// the number of the array;
int key;
int dcbr[34];
int dcbb[17];
//set the value;
for (i = 1; i < 34; i++)
dcbr[i] = i;
for (i = 1; i < 17; i++)
dcbb[i] = i;
srand((unsigned)time(NULL));
//reb ball;
for(i = 1; i < 7;i++){
printf("第 %d 个红球:",i);
key = (rand()%(34-i)) + 1;
printf("%d\n",dcbr[key]);
for (;key <(34-i);key++)
dcbr[key] = dcbr[key+1];
dcbr[34-i] = 0;
}
//blue ball
printf("蓝球:");
key = rand()%16 + 1;
printf("%d\n",dcbb[key]);
return 0;
}
