搜索
查看: 307|回复: 3

随机数哪里不对

[复制链接]
 楼主| 发表于 2019-1-15 20:28:30 | 显示全部楼层 |阅读模式
5啊哈币
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     int a;
  8.     srand((unsigned)time(NULL));
  9.     a = rand();
  10.    
  11.     printf("%d",a);
  12.    
  13.     return 0;
  14. }
复制代码

发表于 2019-1-16 07:41:34 | 显示全部楼层
你是不是把C和C++弄混了            
发表于 2019-1-19 05:54:13 | 显示全部楼层
LZ的C++代码是无法在啊哈C上编译的(C++兼容C,但是C不兼容C++)
正确的C代码:
  1. #include <stdio.h>
  2. #include <time.h>
  3. int main()
  4. {
  5.     int a;
  6.     srand((unsigned)time(NULL));
  7.     a = rand();
  8.     printf("%d",a);
  9.     return 0;
  10. }
复制代码
发表于 2019-1-27 13:08:56 | 显示全部楼层
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() {     int a;     srand((unsigned)time(NULL));     a = rand();     printf("%d",a);     system("pause");     return 0; }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表