Answer to Question #188124 in C for M SAMIULLAH

Question #188124

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


1
Expert's answer
2021-05-02T23:45:45-0400
#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]);
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS