Write a program that prints the result of rolling one fair
dice.
Hint: use the rand() function with range given in
arguments to generate a random integer in the desired
range.
Add a loop to print the sum of rolling 10 fair dice.
Add a second loop to repeat this N times, printing the
sum after each trial.
Maintain an array count[] so that count[k] stores the
number of times the sum is exactly k.
Review your code and eliminate glitches and unnecessary
repetitions if any
#include <stdio.h>
#include <stdlib.h>
int dice() {
return rand() % 6 + 1;
}
int main()
{
int n;
int i, j, k;
int count[61] = {0};
printf("Enter N: ");
scanf("%d", &n);
for (i=0; i<n; i++) {
k = 0;
for (j=0; j<10; j++) {
k += dice();
}
count[k]++;
}
for (i=10; i<=60; i++) {
printf("%2d point count %d times\n", i, count[i]);
}
}
Comments
Leave a comment