Question

in C please, Write the code to simulate rolling three dice and find the sum of...

in C please,

Write the code to simulate rolling three dice and find the sum of the top three faces. Repeat rolling the three dice 10,000 times. Use an array called frequency to have the count of each sum. Pass this array to a function that calculates the maximum number that appears in this array. Print this maximum in main.

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

C CODE:

#include<stdio.h>
#include<stdlib.h>
int maxfreq(int arr[],int n)
{
int max=0;
int maxind=0;
int i;
for(i=0;i<n;i++)
{
if(max<arr[i])
{
max=arr[i];
maxind=i;
}
}
return maxind+3;
}
int main()
{
int rolls=10000;
//Number can be between 3 and 18 then make an array of 16.
int freq[16];
int i;
for(i=0;i<16;i++)
freq[i]=0;
for(i=0;i<rolls;i++)
{
int a=rand()%6+1;
int b=rand()%6+1;
int c=rand()%6+1;
int sum=a+b+c;
freq[sum-3]++;
}
int max=maxfreq(freq,16);
printf("Maximum frequency number is %d\n",max);
return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
in C please, Write the code to simulate rolling three dice and find the sum of...
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
  • Write a C PROGRAM that will simulate rolling a die. When rolling a die, one will...

    Write a C PROGRAM that will simulate rolling a die. When rolling a die, one will get a die face value of 1-6. We can use rand function and math ceiling function to get a random number of 1-6 generated. The program will simulating rolling 5 dice simultaneously and store their face values into an array of size 5. The program will keep rolling the dice and print the following: 1. All face values in one line 2. If any...

  • ( 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...

  • This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no input...

    This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice This problem investigates how...

  • How to write python code that is a dice rolling function that generates random numbers. The...

    How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...

  • 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...

  • PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • 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...

  • Simulate rolling two, fair, six-sided dice 10000 times and adding the "up" faces together each time...

    Simulate rolling two, fair, six-sided dice 10000 times and adding the "up" faces together each time using the "Dice Generator." Plot a relative frequency histogram of the results. Please note that your data will be randomly generated; therefore, select the answer below that is most similar to the histogram that you generated from your random data. If this is challenging, consider all four simulation questions in this assignment at the same time and look for the expected pattern in the...

  • need help with dice excercise For example, if we were writing a calendar program of some...

    need help with dice excercise For example, if we were writing a calendar program of some sort, we might very well use an array with 366 spots to hold the days, not worrying about adding more days to the year. Exercise 23 (C level] For another example, suppose we want to simulate rolling two six-sided dice repeatedly, tallying how many times each total is rolled. We need a memory cell to count the number of times each of the possible...

  • Write a program to simulate rolling three dices simultaneously. Keep rolling these three dices until the...

    Write a program to simulate rolling three dices simultaneously. Keep rolling these three dices until the three dices show the values of “1”, “2”, and “3” (we call this condition 1. The dices are in no particular orders to show these values in this case). Then the program shows the values of the three dices and the number of rolling so far. After that the rolling continues (and counting of the number of rolling continues too) until the first dice...

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