擲骰子
/*******************
隨機產生n次骰子
****************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i, a, x[6],n;
float r = 0;
unsigned seed;
seed = (unsigned)time(NULL);
srand(seed);
for(i=1;i<=6;i++)
x[i]=0;
printf("正修科大 40404113 郭怡勝\n");
printf("丟擲次數: ");
scanf("%d",&n);
for (i=1; i<=n; i++)
{
a = rand() % 6 + 1;
x[a] = x[a]+1;
}
for(i=1;i<=6;i++)
{
r = r + (float)x[i]/n;
printf("x[%d] = %d %f %f \n", i,x[i],(float)x[i]/n,r);
}
system("pause");
return 0;
}