Question

Your task: 1. Study Slides 24 -28 of “FunctionCalling.pptx” 2. Answer the following question in a separate file, called “Assignment#4.pdf”:

• Show all the possible outcomes of the experiment (rolling the dice) using a 2-D table. (see Slides 26, 27)

• What are the events (possible sums) such as 2, 3, … (See Slide 26, 27).

Example: Number Distribution so Generating numbers that conform a given distribution so Create an array to store all possibleExample: Number Distribution Example: Use rand() to generate the sum when rolling two fair dice. #include <stdio.h> #include

0 0
Add a comment Improve this question Transcribed image text
Answer #1

rand() function of the stdlib.h library generates a random integer.

Here is the C code for the generation of the random numbers and die sum frequency:-

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define RUN 1000000

#define EVENT 11

#define OUTCOME 36

int main() {

int i, randNum, diceprob[EVENT]={0,0,0,0,0,0,0,0,0,0,0};

int twodices[OUTCOME]={2,3,4,5,6,7, 3,4,5,6,7,8, 4,5,6,7,8,9, 5,6,7,8,9,10, 6,7,8,9,10,11, 7,8,9,10,11,12 };

int dicerealprob[EVENT]={1,2,3,4,5,6,5,4,3,2,1};

srand(time(0)); // this is the seed given to the rand() function so that same set of random no. are not generated everytime we run the program

for(i=0;i<RUN;i++){ // running the simulation for RUN or 1000000 times

randNum= rand()%OUTCOME; // randNum would be a number between 0 and 35(both inclusive), that is the indices of the twodices array

diceprob[twodices[randNum]-2]++; // incrementing the corresponding outcome's frequency in diceprob array

}

for(int j=0;j<EVENT;j++){

printf("%d ",diceprob[j]);

}

}

Here is a snapshot of my program and its output in an online IDE:-

X + C Computer Science question Che X Coding Blocks IDE C o ide.codingblocks.com * Apps Chrome Web Store... torukjaat007 (Tar

Add a comment
Know the answer?
Add Answer to:
Your task: 1. Study Slides 24 -28 of “FunctionCalling.pptx” 2. Answer the following question in a...
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
  • 1T (startIndex< size) ( 22 23 someFunction(b, startIndex +1, size); printf("%d ", b[startIndex]); 24 25 26...

    1T (startIndex< size) ( 22 23 someFunction(b, startIndex +1, size); printf("%d ", b[startIndex]); 24 25 26 (Dice Rolling) Write a program that simulates the rolling of two dice. The program should rand twice to roll the first die and second die, respectively. The sum of the two values should then be calculated. [Note: Because each die can show an integer value from 1 to 6, then the sum of the two values will vary from 2 to 12, with 7...

  • This question is due my 11:50pm EST One die is rolled 2 times in a row.  ...

    This question is due my 11:50pm EST One die is rolled 2 times in a row.          The observation is the number that comes up on each roll (rolling 2 and 5 is not the same as rolling 5 and 2). Describe one outcome and find a number of outcomes. Write all outcomes of the sample space S   (you can use … notation to indicate many numbers of cases).      : “pairs are rolled” (both dice come up the same number)     Write...

  • // This program creates a simulated player who takes one turn in the // Pig dice...

    // This program creates a simulated player who takes one turn in the // Pig dice game. The simulated player keeps rolling the die until // the total for the turn is 20 or greater, or until a 1 is rolled. // If a 1 is rolled, the player's score for the turn is 0. Otherwise // the player's score is the sum of the rolls for the turn. // ///////////////////////////////////////////////////////////////////// #include<iostream> #include<cstdlib> #include<time.h> using namespace std; int randNumGen(int upper,...

  • please answer question 1 and 2 that go together 2/3 3/4 + 1/4 equals Probability of...

    please answer question 1 and 2 that go together 2/3 3/4 + 1/4 equals Probability of child carrying RR equals to 1/4 Probability of child carrying Rr equals to 1/2 1/4 Probability of child carrying R_equals to 1/4 1/2 1/4 + 1/2 equals 3/4 R RR Rr What is the chance that the child of parents, who are both heterozygous for the Rand Talleles, carries at least one dominant Rallele and expresses the recessive 1/4 x 1/4 equals 1/16 Probability...

  • Please shoe your work for 1 & 2 I need to understand them well,, Include all...

    Please shoe your work for 1 & 2 I need to understand them well,, Include all work in a neat and well organized presentation. Grading is based on the quality, thoroughness, and correctness of the work provided. Two six-sided dice will be rolled once and the numbers (number of dots) on each dice is to be recorded. Define events E the sum of the two dice is i,i2,3...2. List all the outcomes in the Sample Space. a. b. Calculate the...

  • Hello, I am having trouble with a problem in my C language class. I am trying...

    Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct {     char name[MAX_SIZE1];     int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...

  • Thank you!!! 4.1 [2 pts. int rollO Define a function roll() that takes no arguments, and...

    Thank you!!! 4.1 [2 pts. int rollO Define a function roll() that takes no arguments, and returns a random integer from 1 to 6. Before proceeding further, we recommend you write a short main method to test it out and make sure it gives you the right values. Comment this main out after you are satisfied that roll() works. Remenber:texibook Seciion 49 is on randormness, and Chapier 5is on functions. int getKandomNumber return 4 l chosen by fair dice roll....

  • Example Consider the following dice game. A pair of standard ( fair ) dice are repeatedly...

    Example Consider the following dice game. A pair of standard ( fair ) dice are repeatedly rolled. If a ’ 7 ’ comes up before an ’ 11 ’ , then the player wins, otherwise the player loses. Let W be the event that the player wins. Find P(W). To say the dice are fair is equivalent to assuming that Laplace’s rule holds and the 36 possible outcomes for a throw of the dice are equally likely. For convenience, an...

  • Answer question 1 & 2 asap please. The question is indeed complete. Question 1 Fill in...

    Answer question 1 & 2 asap please. The question is indeed complete. Question 1 Fill in the P(X=x) values to give a legitimate probability distribution for the discrete random variable X, whose possible values are -6, -5, 0,5, and 6. Value of x P(x = x) 0.12 -5 0.21 0 0 $ 0.12 6 ? Question 2 Suppose that the genders of the three children of a certain family are soon to be revealed. Outcomes are thus triples of "girls"...

  • PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement...

    PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement an algorithm to determine the next greater element of an element in an array in Θ(n) time, where 'n' is the number of elements in the array. You could use the Stack ADT for this purpose. The next greater element (NGE) for an element at index i in an array A is the element that occurs at index j (i < j) such that...

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