week 8
2014-04-15 19:55
218 查看
用rand编写一个程序,出来一个随机数
随机输出10个没有重复数字的数
/* Note:Your choice is C IDE */ #include "stdio.h" #include "stdlib.h" main() { int ia; ia=rand(); printf("the random number is %d \n",ia); }随机输出1~45之间的数
/* Note:Your choice is C IDE */ #include "stdio.h" #include "stdlib.h" main() { int ia,ib; ia=rand(); ib=ia%45+1; printf("the random number is %d \n",ib); }随机输出10个数
/* Note:Your choice is C IDE */ #include "stdio.h" #include "stdlib.h" main() { int ia,ib,i; for(i=0;i<10;i++) { ia=rand(); ib=ia%45+1; printf("the random number is %d \n",ib); }}
随机输出10个没有重复数字的数
/* Note:Your choice is C IDE */ #include "stdio.h" #include "stdlib.h" #define N 25 main() { int ia,ib,i,j; int students ; for(i=0;i<N;i++) { ia=rand(); ib=ia%45+1; if(i>0)/*因为第一个数不可能重复 */ { for(j=0;j<=i-1;j++) { if(ib==students[j]) { ib=rand()%45+1; j=-1;/*j=-1,继续返回执行for循环*/ } } } students[i]=ib; printf("the random number is %d \n",ib); } }
相关文章推荐
- lua -- 事件响应与局部变量
- leetcode-Pascal's Triangle II (2014.3.11)
- 赋值运算符函数
- 助你解决新手开车四大问题 为您支招
- 伪分布单机启动
- [物理学与PDEs]第5章第2节 变形的描述, 应变张量 2.3 位移梯度张量与无穷小应变张量
- leetcode-Permutations(2014.2.3)
- Java中的异常
- 26条安全开车经验 开车20年老司机分享
- leetcode-Permutations II(2014.2.4)
- 第八周 复数类中的运算符重载1
- shellcode之一:栈溢出
- 62.笨小熊
- CATextLayer使用
- 自动挡车挡位的基本知识介绍
- Canonical 已经开始讨论关于 Convergence 与 Ubuntu 14.10 的功能
- zoj 3777 Problem Arrangement
- 网络编程——TCP连接
- 0804
- [物理学与PDEs]第5章第2节 变形的描述, 应变张量 2.2 Cauchy - Green 应变张量