全部问题 > 当前问题

关于随机数的问题!!!!!

和老师那个程序基本一样,但是怎么也运行不了,求救!!!!!!!


#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");
    }

葬爱 2018-4-13 19:37:33

共 1 个回答

【C语言答疑】小陈 2018-5-30 15:49:38

在运行时,整个程序下来是没有显示错误指令的。但是在程序的while语句中,b=rand()+100;这一条语句并没有使得b产生随机数。应该改为b=rand()%100;image.png

问题来自: Ëæ»úÊý