Question

In: Computer Science

Write a program to simulate an experiment flipping three coins. Each time the three coins are...

Write a program to simulate an experiment flipping three coins. Each time the three coins are flipped, is called a “trial”. A coin flip can randomly result in either “Heads” (1) or “Tails” (0) Allow the user to enter the number of “trial”s to simulate. Print out each coins’ result after each “trial”. Use seed value 1234. Tally up and determine what percentage of “trial”’s all three coins land on “Heads” in the simulation. C language

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<stdio.h>

#include<stdlib.h>

int main(){

    srand(1234);

    int n, i, result_coin1, result_coin2, result_coin3, heads = 0;

    printf("enter the number of \"trial\"s to simulate: ");

    scanf("%d", &n);

    for(i=1; i<=n; i++){

        result_coin1 = rand()%2;

        result_coin2 = rand()%2;

        result_coin3 = rand()%2;

        heads = 0;

        printf("Trial %d:\t", i);

        if(result_coin1){

            printf("Heads");

            heads++;

        }

        else

            printf("Tails");

        printf("\t");

        if(result_coin2){

            printf("Heads");

            heads++;

        }

        else

            printf("Tails");

        printf("\t");

        if(result_coin3){

            printf("Heads");

            heads++;

        }

        else

            printf("Tails");

        printf("\tHeads(%%): %.2f\n", (heads/3.0)*100);

    }

    return 0;

}


Related Solutions

Write a program that simulates flipping a coin repeatedly until three consecutive        heads are...
Write a program that simulates flipping a coin repeatedly until three consecutive        heads are tossed. The program should then display the total number of times the coin was        flipped. The user does not have to enter any information and we must use a while loop.
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program that simulates the flipping of a coin n times, where n is specified...
Write a program that simulates the flipping of a coin n times, where n is specified by the user. The program should use random generation to flip the coin and each result is recorded. Your program should prompt the user for the size of the experiment n, flip the coin n times, display the sequence of Heads and Tails as a string of H (for Head) and T (for Tail) characters, and display the frequencies of heads and tails in...
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Consider an experiment in which three different coins (say a penny, a nickel, and a dime...
Consider an experiment in which three different coins (say a penny, a nickel, and a dime in that order) are tossed and the sequence of heads and tails observed. For each of the following pairs of events, A and B, give the subset of outcomes that defines the events and state whether the pair of events are mutually exclusive, collectively exhaustive, neither or both. (a) A: The penny comes up heads. (b) A: The penny comes up heads. B: The...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and three copper coins. Hat 2 contains four gold coins and six silver coins. Hat 3 contains three gold coins and seven copper coins. We randomly select one coin from each hat. (a) The outcome of interest is the colour of each of the three selected coins. List the complete sample space of outcomes and calculate the probability of each. (b) Let X be the...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and three copper coins. Hat 2 contains four gold coins and six silver coins. Hat 3 contains three gold coins and seven copper coins. We randomly select one coin from each hat. (a) The outcome of interest is the color of each of the three selected coins. List the complete sample space of outcomes and calculate the probability of each. (b) Let X be the...
Coin toss experiment In this experiment, determine the number of heads and tails after flipping a...
Coin toss experiment In this experiment, determine the number of heads and tails after flipping a coin for 1000 times. Use two different methods to find number of heads and tails Use for loops Use vectors in MATLAB. Repeat this experiment to find running average of flipping a coin for 200 and 2000 times. Plot the running average for two experiments using subplot functions
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT