如何用Visual C++6.0编出一个从1到100随机抽取一个数的程序?

我是初学者,只知道
#include <stdio.h>

void main()
{
int a;
a=rand()*100+1;
printf("%d",a);
}
我只学了不到3天。。。请问应该怎么改,这样运行出的错误是:error C2065: 'rand' : undeclared identifier
Rand应该怎么定义?
是VC哟,谢谢
还是不行,这次的错误是error C2018: unknown character '0xa3'

我直接给你代码吧,我刚刚也有个地方说错了。

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int a;
srand(time(NULL));
a = rand()%100+1;
printf("%d", a);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-05
#include <stdlib.h>
#include <time.h>

先通过srand函数来初始化种子
因为随机数是通过取种子得到的

void main()
{
int i;
srand((unsigned)time(NULL));
i=rand()%100;
printf(

……
就这样就能取100以内随机数了
相似回答