急 求c语言随机抽取姓名源码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct
{
char str[20]; //名字
int no; //号码
}a[99]={{" ",0}}; //初始化
int main()
{
FILE *fp;
char ch;
int i,n=0,choice,who;
fp=fopen("name.txt","r");
if(fp==NULL)
{
printf("can not open the file\n");
return 1;
}
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')n++; //一行一个名字,计算人数
}
rewind(fp);
for(i=0;i<n;i++)
{
a[i].no=i; //每人对应的号码
fscanf(fp,"%s\n",a[i].str);
}
srand(time(NULL));
for(i=1;i<n;i++)
{
printf("=============\n1.抽取 0.退出\n=============\n");
scanf("%d",&choice);
if(choice==1)
{
loop:
who=rand()%n+1;
if(a[who].no==0)goto loop;
puts(a[who].str);
a[who].no=0; //抽取过的标志为0
}
else break;
}
fclose(fp);
return 0;
}
佚名
2024-09-29 14:22:10
类似问题(10)
-
佚名2024-09-29 05:44:07
问c语言如何随机输出同学名字?
答随机数函数int rand(void);除以3.余数是几0,1,2!多看书。
-
佚名2024-09-29 15:55:12
问c语言 随机点名
答#include<stdio.h>#include<stdlib.h>#include <time.h>#define STU_NUM_MAX...
-
佚名2024-09-29 15:20:11
问c语言如何随机输出同学名字?
答#include <stdlib.h>#include <time.h>int randonNumber(){int i,number;srand(...
-
佚名2024-09-29 11:50:17
问易语言取不重复随机数
答.版本 2.子程序 取随机数字, 文本型.参数 个数, 整数型.局部变量 去重复, 节点.局部变量 a, 文本型.局部变量 i, 整数型.局部变量 str, 文...
-
佚名2024-09-29 18:15:03
问c语言 选猴王问题 源代码 急需! 最好是原创的
答#include <stdio.h>int main(){ int n,m, f = 0; scanf("%d%d",&n,&...
-
佚名2024-09-29 08:00:00
问跪求大神帮忙,用C语言编程,求代码,急!!! ⑴实现三种以上静态或动态查找方法,查找表中的数据随机
答这个问题建议你发到shx.io这个网站试试,里面程序员非常多。你发个问题,如果三分钟没人回复你,你私信我,我找朋友帮忙
-
佚名2024-09-29 08:00:00
问怎样用c语言产生一个0到100的随机数
答rand()%101。
-
佚名2024-09-29 08:00:00
问C语言源文件的后缀名是.c,C++语言源文件的后缀名是什么呢?
答这是现在不同标准下给出的扩展名:Unix:C, cc, cxx, cGNU C++:C, cc, cxx, cpp, c++Digital Mars:cpp, ...
-
佚名2024-09-29 08:00:00
问易语言怎么写一个随机抽名的程序?
答已发送,请查收
-
佚名2024-09-29 08:00:00
问c语言求助 急急
答for循环由三部分组成,例如for(int y=0;y<10;y++) {主体 }其中int y=0 是初始条件,y<10是循环条件,y++是 变...
风水
起名
网名
- 1 微信啥网名好听有意义
- 2 闺蜜二个字网名大全
- 3 网名带彦昵称
- 4 你什么情况下会改网名
- 5 搜一个四字的微信昵称
- 6 互道昵称
- 7 有颜字的qq昵称
- 8 qq昵称霸气超拽闺蜜二人
- 9 流行微信昵称大全2015
- 10 王者荣耀昵称限制几个字
说说
- 1 枪神纪qq个性签名
- 2 很拽得个性签名
- 3 小宝宝学投篮个性签名
- 4 爱情分手说说
- 5 发表说说喝青汁了
- 6 为油盐柴米油盐发愁的说说
- 7 爱情让人痛彻心扉的说说
- 8 父亲节端午节幽默说说
- 9 aa制夫妻的说说
- 10 母亲节送蜂蜜说说