关于随机数的问题!!!!!
和老师那个程序基本一样,但是怎么也运行不了,求救!!!!!!!
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int a,b,t;
time(&t);
srand(t);
while(1)
{
system("cls");
a=rand()%100;
b=rand()+100;
printf("a=%d\nb=%d\na+b=%d",a,b,a+b);
system("pause");
}
}
在运行时,整个程序下来是没有显示错误指令的。但是在程序的while语句中,b=rand()+100;这一条语句并没有使得b产生随机数。应该改为b=rand()%100;