抽奖程序 C/C++

抽奖程序

#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');
}
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码抽奖代码
离线抽奖程序可以使用C语言实现。首先,我们需要定义一个结构体来存储参与抽奖的人员信息,包括姓名、电话号码等。然后,我们可以使用C语言的随机数生成函数来随机抽取幸运的中奖者。 首先,我们需要定义一个结构体来存储参与抽奖的人员信息,包括姓名、电话号码等: ```c #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct { char name[50]; char phone[20]; } Participant; ``` 然后,我们可以写一个函数来进行抽奖,从参与抽奖的人员中随机选取中奖者: ```c void drawWinner(Participant participants[], int numParticipants) { srand(time(NULL)); int winnerIndex = rand() % numParticipants; printf("恭喜 %s 获得抽奖大奖!\n", participants[winnerIndex].name); } ``` 最后,我们可以在main函数中实现用户输入参与抽奖的人员信息,并调用抽奖函数进行抽奖: ```c int main() { int numParticipants; printf("请输入参与抽奖的人员数量:"); scanf("%d", &numParticipants); Participant participants[numParticipants]; for (int i = 0; i < numParticipants; i++) { printf("请输入第%d位参与者的姓名和电话号码:", i+1); scanf("%s %s", participants[i].name, participants[i].phone); } drawWinner(participants, numParticipants); return 0; } ``` 通过以上代码,我们就可以实现一个基于C语言的离线抽奖程序,用户可以输入参与抽奖的人员信息,然后程序会随机抽取出中奖者。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值