单链表_生成100个随机数_查询并输出大于K的数
2016-09-15 11:20
316 查看
生成100个随机数,并查询大于k的输出。
#include"stdio.h" #include"time.h" #include"stdlib.h" typedef struct node { int num; struct node * next; }node; void chaxun(int k,node *h)//查询大于等于k的并输出 { node *p=h->next; int jishu=0; while(p->next!=NULL) { if(p->num>=k) { printf("第 %5d 个结点的 %5d 大于等于 %5d\n",jishu,p->num,k); jishu++; } p=p->next; } } int main() { srand(time(NULL));//生成时间种子。 int a[100];//定义100个整数 for(int i=0;i<100;i++) { a[i]=rand()%10000;//生成100个随机数 } node *h=(node *)malloc(sizeof(node));//新建头节点h h->next=NULL; node *p=h; for(int i=0;i<100;i++) { node *r=(node *)malloc(sizeof(node)); r->num=a[i]; r->next=NULL; p->next=r; p=r; } printf("查询大于等于:"); printf("_______的数\b\b\b\b\b"); int k; scanf("%d",&k); printf("\n"); chaxun(k,h); node *r2=h; while(r2->next!=NULL) { node *r3=r2->next; r2=r3->next; free(r3); } free(h); return 0; }
相关文章推荐
- 笔试题:生成100个-100到100的随机数,用不保存随机数的方式输出最大值最小值
- kettle生成100个随机数,并统计小于等于50和大于50个数
- 【Java每日一题01】使用java.lang.Math类,生成100个0到99之间的随机整数,找出它们之中的最大者和最小者,并统计大于50的整数个数
- JAVA 生成随机数数组,并排序输出
- 生成100个100~50之间的随机数 一行一个数
- C/C++ 使用rand()组合形式生成大于15位的随机数时存在的问题
- 小程序-----Java实现输出5个大于100,小于1000的随机数
- 输入数列,以某数为结束标志,以“先进先出”方式生成单链表,输出表中各结点的值;再求表中结点的平均值、最大值、最小值。
- C表示摄氏温度和随机数生成输出的问题
- 定义一个100长度的整型数组,使用rand函数生产随机数对每个元素进行赋值,顺序遍历该数组,输出所有值大于50的数
- 随机生成一个对称矩阵,并输出。(究极版本,可以每一次都改变矩阵的随机数且不同,采用do while退出条件循环)
- Java生成10个1000以内的随机数并用消息框显示数组内容然后求和输出
- mysql 查询一个字段,生成连接字符串输出 统计函数 group_concat concat concat_ws
- 生成k个不同的随机数,从m到n,并输出最大值的程序代码
- vb.net控制台 random类 随机字符,随机数 (生成4个随机3位数倒序输出)
- 单链表创建、输出、逆转、查询
- JAVA 生成随机数数组,并排序输出
- 随机生成100个不重复的随机数
- 我的java之路——找出100个范围在0-99的随机数的最大值和最小值并统计大于50的整数的个数
- SQL 生成6位随机数并MD5加密输出