70,037
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char i,seed[10]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int j,count[10];//存放1~10的10个统计量
for (i=0; i<10;i++)
{
for (j=0; j<10; j++)
count[j] = 0;
srand(seed[i]);
for (j=0; j<1000; j++)
count[rand()%10]++; //应该产生的随机数是0-9啊。。。
printf("seed = %d:\n",seed[i]);
for (j=0; j<10; j++)
printf("%d: %d times:\t",j+1,count[j]);
printf("\n");
}
return 0;
}
//lianxi5.c
#include <stdio.h>
#include <stdlib.h>
#define WIDTH 10
int main(void)
{
int i,seed[WIDTH] = {0,1,2,3,4,5,6,7,8,9};
int j,k,count[WIDTH];
for(i=0;i<WIDTH;i++)
{
for(j=0;j<WIDTH;j++)
count[j] = 0;
srand(seed[i]);
for(j=0;j<1000;j++)
{
k = rand() % 10 + 1;
count[k-1]++;
}
printf("seed = %d:\n",seed[i]);
for(j=0;j<10;j++)
printf("%d: %d times:\t",j+1,count[j]);
puts("\n");
}
return 0;
}