the dice-rolling program to also print a histogram.


#include
#include

int main()
{
int i;
int d1, d2;
int a[13];

for(i = 2; i <= 12; i = i + 1)
a[i] = 0;
for(i = 0; i < 100; i = i + 1)
{
d1 = rand() % 6 + 1;
d2 = rand() % 6 + 1;
a[d1 + d2] = a[d1 + d2] + 1;
}
for(i = 2; i <= 12; i = i + 1)
{
printf("%d: %d\t", i, a[i]);
printnchars('*', a[i]);
printf("\n");
}
return 0;
}

No comments:

Post a Comment