c语言生成 o~100随机数!
2016-02-25 20:45
323 查看
还在学习中,先贴上代码,等待以后自己解答,第二种为什么编译失败!
#include <stdio.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
#define BOOL int
#define TRUE 1
#define FALSE 0
int main(void)
{
//正确的
/*
int chosen=0;
int i=0;
srand((unsigned)time(NULL));
for(;i<100;i++){
chosen=1+rand()%100;
printf("生成随机数:%d \n",chosen);
}*/
// vc中编译失败!
int i=0;
srand((unsigned)time(NULL));
int chosen=0;
for(;i<100;i++){
chosen=1+rand()%100;
printf("生成随机数:%d \n",chosen);
}
return 0;
}
#include <stdio.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
#define BOOL int
#define TRUE 1
#define FALSE 0
int main(void)
{
//正确的
/*
int chosen=0;
int i=0;
srand((unsigned)time(NULL));
for(;i<100;i++){
chosen=1+rand()%100;
printf("生成随机数:%d \n",chosen);
}*/
// vc中编译失败!
int i=0;
srand((unsigned)time(NULL));
int chosen=0;
for(;i<100;i++){
chosen=1+rand()%100;
printf("生成随机数:%d \n",chosen);
}
return 0;
}
相关文章推荐
- c++中类的多态和虚函数的使用
- 20160211.CCPP体系详解(0021天)
- c语言字符串 数字转换函数大全
- 20160210.CCPP体系详解(0020天)
- C语言运算优先级
- C++STL中的标准模板——优先队列
- 俄罗斯方块C++源码
- c++中使用struct,struct中有指针
- C++中vector模板详解
- 20160209.CCPP体系详解(0019天)
- 1050. String Subtraction (20)
- C语言函数调用机制
- 字符个数统计
- C/C++常用头文件及函数汇总
- C语言知识整理(三)
- c++常见面试题30道
- 1048. Find Coins (25)
- c++ 关联容器
- c++ 泛型算法
- 1047. Student List for Course (25)