✔ 最佳答案
/* here is the program requested. As you probably understand, it will produce
numbers around 400 as the result, and not 4000, as we throw only 600 times.
However, you'll get 4000 if you change the value of nTimes to 6000.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
const int nTimes=600;
srand(time(NULL));
int i,k, sum=0;
for(i=0;i<nTimes;i++)
{
k=rand()%6+1;
if(k%2==0||k%3==0)sum++;
}
printf("Number of throws=%d\nNumber of outcomes divisible by 2 or 3=%d\n",nTimes,sum);
return 0;
}