抽奖程序 C/C++

来源:互联网 发布:软件测试平均工资 编辑:程序博客网 时间:2024/05/24 01:46

抽奖程序

#include<stdio.h>#include<stdio.h>#define MAX 20int 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');}
0 0
原创粉丝点击