注:本程序由Visual Studio 2015编写,与VC++6.0稍有区别,复制到VC++6.0注释掉“#include “stdafx.h””即可运行,复制到VS可直接运行。
#include “stdafx.h”
#include
#include <stdlib.h>
#include <time.h>
int main()
{
int i;
//时间种子,从1900年1月1日到现在的时间秒数,使rand()产生一个随机数
srand((unsigned)time(NULL));
//提示,可通过取模的方式控制数的范围
//如下代码,获得0-99的数字
i = rand()%100;
printf(“生成随机数:%d\n\n”, i);
return 0;
}
以上代码均为原创,存在不足还请见谅!
如有转载请注明来源: www.dreamload.cn/blog/?p=471&preview=true (洋葱先生-杨少通)