以下程序随机产生一注双色球,对比程序自己加
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
void chongf(int* ar, int d)//判断是否重复数字,如果是则重新生成一个随机数
{
for(int i = 0; i<d; i++)
{
if(ar[i] == ar[d])
{
ar[d] = rand() % 33 + 1;
chongf(ar, d);
}
}
}
int main()
{
int arr[7],temp;
srand(time(0));
for(int i = 0; i<6; i++)
{
arr[i] = rand() % 33 + 1;
chongf(arr, i);
}
arr[6]=rand() % 16 + 1;
for(int i=0;i<5;i++)
for(int j=i+1;j<6;j++)
{
if(arr[i]>arr[j])
{temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
printf("红球号码为:");
for(int i = 0; i<6; i++)
{
printf("%d
",arr[i]);
}
printf("\n");
printf("蓝球号码为:");
printf("%d\n",arr[6]);
system("pause");
return 0;
}