返回列表 发帖

实例029错误

#include <stdlib.h>
main() {
        int a,b;
        int sum;
        a=rand()%100;                /*调用库函数rand产生100内的随机数*/
        srand(time());                /*调用scrand函数根据括号内的种子不同,可以是下次产生的随机数不同*/
        b=rand()%100;                /*受srand函数的影响,产生随机数*/
        printf("%d +%d = ",a,b);
        scanf("%d",&sum);        /*输入计算结果*/
        if (sum==a+b)                 /*输出判断*/
                printf("  Answer is true\n");
                                        /*答案正确的输出*/
        else
                printf("  Answer is false\n");
                                        /*答案错误的输出*/
}
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友

--------------------Configuration: ex_29 - Win32 Debug--------------------
Compiling...
29.cpp
F:\c\ex\ex_29\29.cpp(6) : error C2065: 'time' : undeclared identifier
F:\c\ex\ex_29\29.cpp(8) : error C2065: 'printf' : undeclared identifier
F:\c\ex\ex_29\29.cpp(9) : error C2065: 'scanf' : undeclared identifier
F:\c\ex\ex_29\29.cpp(16) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

29.obj - 3 error(s), 1 warning(s)

TOP

三个都试了,还是老样子

TOP

srand(time());  
大哥可以讲解一下这个吗?

TOP

返回列表