#include<stdio.h>
#include<stdio.h>
#define MAX 20
int FLAG[MAX];
int count;
void select(int *people,int count);
void show(int *show,int count);
int main(void)
{
int people[MAX],i;
srand((unsigned int)time(NULL));
for(i=0;i<MAX;i++)
{
people[i] = rand();
}
show(people,MAX);
printf("\ninput the size you want to pick in %d people([ctr+z] to quit):",MAX-count);
while(scanf("%d",&i) == 1)
{
if(i > MAX-count)i = MAX-count;
select(people,i);
count += i;
if(count < MAX)
printf("\ninput the size you want to pick in %d people([ctr+z] to quit):",MAX-count);
else
break;
}
putchar('\n');
system("pause");
return 0;
}
void select(int *people,int count)
{
int i=0,num;
while(i<count)
{
num=rand()%MAX;
if(FLAG[num] != 1)
{
printf("%d:%d ",num+1,people[num]);
FLAG[num] = 1;
i++;
}
}
putchar('\n');
}
void show(int *show,int count)
{
int i;
for(i=0;i<count;i++)
{
printf("%-6d ",show[i]);
if(i%10 == 9)
putchar('\n');
}
if(i%10 != 0)
putchar('\n');
putchar('\n');
}
抽奖程序 C/C++
最新推荐文章于 2024-05-27 16:06:55 发布