Question

1T (startIndex< size) ( 22 23 someFunction(b, startIndex +1, size); printf(%d , b[startIndex]); 24 25 26 (Dice Rolling) Wri
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define MAX 36000


int main()
{
   int i,sum;
   int dice1,dice2;
   int arr[11]={0};

   srand(time(0));

   for(i=0;i<MAX;i++)
   {
       dice1 = (rand()%6)+1;
       dice2 = (rand()%6)+1;

       sum = dice1+dice2;
       arr[sum-2]++;
       /*
       arr stores the occurence of sum from 2 to 12

       element at index 0 corresponds to occurence of sum 2
       element at index 1 corresponds to occurence of sum 3
       element at index 2 corresponds to occurence of sum 4
       and so on......

       */
   }

   printf("occurences : \n");

   for(i = 2;i<13;i++)
       printf("%5d\t",i);
   printf("\n");

  
   for(i= 0;i<11;i++)
       printf("%5d\t",arr[i]);


   printf("\n\nExpected occurence of sum 7 Is: %lf percent\n\n",(1.0/6.0)*100);


   printf("\nObserved Occurence of sum 7 Is : ");
   printf("%lf percent\n\n",((float)arr[5]/MAX)*100);


   return 0;
}

/*output

occurences :
2   3   4   5   6   7   8   9   10   11   12  
981   2038   2877   3962   5035   5932   5088   4018   3061   2000   1008  

Expected occurence of sum 7 Is: 16.666667 percent


Observed Occurence of sum 7 Is : 16.477777 percent


*/

Add a comment
Know the answer?
Add Answer to:
1T (startIndex< size) ( 22 23 someFunction(b, startIndex +1, size); printf("%d ", b[startIndex]); 24 25 26...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please do it in C++ Write a program that simulates the rolling of two dice. The...

    please do it in C++ Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2and 12...

  • Write a java program that simulates the rolling of four dice. The program should use random...

    Write a java program that simulates the rolling of four dice. The program should use random number generator to roll dice. The sum of the four values should then be calculated. Note that each die can show an integer value from 1 to 6, so the sum of the four values will vary from 4 to 24, with 14 being the most frequent sum and 4 and 24 being the least frequent sums. Your program should roll the dice 12,960...

  • ( Java Programming ) Write an application to simulate the rolling of two dice. The application...

    ( Java Programming ) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12...

  • Rolling Dice 2. A pair of dice is rolled. Here is the sample space (all of...

    Rolling Dice 2. A pair of dice is rolled. Here is the sample space (all of the possible outcomes) of rolling a pair of dice. First Die a) In how many different ways can we roll a 7 (as the sum of the two dice)? What is the probability of rolling a 7? 2 3 4 5 6 7 3 4 5 6 7 8 b) In how many ways can we roll a sum that is divisible by 3?...

  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • Complete each problem separately and perform in python. 1. Create a script that will roll five...

    Complete each problem separately and perform in python. 1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex: Hit enter to roll 1,4,3,6,6 Hit enter to roll 3,5,1,2,1 Hit enter to roll 4,3,4,2,6 2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print...

  • in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation...

    in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation program to estimate the winning chance of the Craps game. Craps is a popular dice game played in casinos. Here is how to play: Roll two dice. Each die has 6 faces representing values 1,2,3,4,5,and 6, respectively. Check the sum of 2 dice. If the sum is 2, 3, or 12 (called craps), you lose; if the sum is 7 or 11 (called natural),...

  • hey, struggling with this assignment, wondering if if I could get some help. Here is the...

    hey, struggling with this assignment, wondering if if I could get some help. Here is the project details The following lists a Dice class that simulates rolling a die with a different number of sides. The default is a standard die with six sides. The rollTwoDice function simulates rolling two dice objects and returns the sum of their values. The srand function requires including cstdlib. my class ------------------------------------ class Dice { public: Dice(); DIce(int numSides); virtual int rollDice()const; protected: int...

  • The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values...

    The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values together. 2. Choose whether to roll the dice again or pass the dice to your opponent. 3. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your...

  • 3) We roll 2 fair dice. a) Find the probabilities of getting each possible sum (i.e....

    3) We roll 2 fair dice. a) Find the probabilities of getting each possible sum (i.e. find Pr(2), Pr(3), . Pr(12) ) b) Find the probability of getting a sum of 3 or 4 (i.e.find Pr(3 or 4)) c) Find the probability we roll doubles (both dice show the same value). d) Find the probability that we roll a sum of 8 or doubles (both dice show the same value). e) Is it more likely that we get a sum...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT