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

1. Dice Rolling (15 points)<?xml:namespace prefix = o ns = \"urn:schemas-microso

ID: 3534206 • Letter: 1

Question

1.      Dice Rolling (15 points)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Write a program that simulates the roll of two dice using the random number generators. You will call the rand () function once for each dice. Each rand() call will return a number between 1 and 6.   Create a do loop to generate a total of 100 dice rolls and calculate the sum of the two dice values.   You should create an array to count the number of occurs of each total between 2 and 12.   Output the results of the Array.

Array (0) has the number of times a two total was generated.

Array (1) has the number of times a three total was generated

Array (2) counts the number of times a total of four was generated etc.

Explanation / Answer

#include<stdio.h>

int main()

{

int ar0[100],ar1[100],ar2[100];

int i,j,k,l,m,count=0;

for(i=0;i<100;i++)

{

j=rand()%6;

if(j==0)

j=6;

ar0[i]=j;

k=rand()%6;

if(k==0)

k=6;

ar1[i]=k;

ar2[i]=j+k;

}

printf("values in array 1 ");

for(i=0;i<100;i++)

printf("%d ",ar0[i]);

printf("values in array 2 ");

for(i=0;i<100;i++)

printf("%d ",ar1[i]);

printf("values in array 3 ");

for(i=0;i<100;i++)

printf("%d ",ar2[i]);

for(j=2;j<13;j++){

for(i=0;i<100;i++)

{

if(ar2[i]==j)

count++;

}

printf("number of times %d was generated is %d ",j,count);

count=0;}

}