Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that simulates the rolling of two dice. the program should use r

ID: 3546404 • Letter: W

Question

write a program that simulates the rolling of two dice. the program should use rand() to roll the first dice and should use rand() again to roll the second dice. the sum of the two values should then be calculated. note: since each dice can show an integer value from 1 to 6, then the sum of the two values will vary from 1 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. your program should roll the two dice 36.000 times. use a single-dimential array frequency to tally the numbers of times each possible sum appears. to calculate the i-th element of prob. use the formula: prob[i]= frequency[i]/36,000. display both arrays frequency and prob in a tabular format.

Explanation / Answer

#include #include #include int main(void) { int number1,number2,sum,total=0,i; int frequency[13]={0}; int expected[ 13 ] = { 0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1}; srand(time(NULL)); for (i = 0; i < 36000; i++) { sum=0; number1=1+rand()%6; number2=1+rand()%6; sum=number1+number2; frequency[sum]++; } for (i = 0; i < 13; i++) { total+=frequency[i]; } printf("Sum Total Expected Actual "); for (i = 2; i < 13; i++) { printf("%2d %8d %f %9f ",i,frequency[i], 100.0*expected[i]/36,100*(double)frequency[i]/total ); } getch(); return 0; }