#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
int t,i,n,y;
time(&t);
srand(t);
while(1)
{
system("cls");
printf("请输入生成随机数的个数:");
scanf("%d",&n);
if(n==0)
break;
y=0;
for(i=1;i<=n;i++)
{
printf("%d\n",rand());
y=y+rand();
}
printf("y=%d\n",y);
system("pause");
}
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
int t,i,n,y,s;
time(&t);
srand(t);
while(1)
{
system("cls");
printf("请输入生成随机数的个数:");
scanf("%d",&n);
if(n==0)
break;
y=0;
for(i=1;i<=n;i++)
{
s=rand();
printf("%d\n",s);
y=y+s;
}
printf("y=%d\n",y);
system("pause");
}
}
因为rand()是一个库函数,所以像你之前那样用的话是不行的,因为你用一次这个rand()的值就会变一次,自然就不会是显示出来的那些随机数的和了