Question

In: Computer Science

write c program to generate 6 numbers to simulate rolling of a dice . use while...

write c program to generate 6 numbers to simulate rolling of a dice . use while loop to run 100 and 10000 times. print out how many times it generates 1, 2,3,4,5,6.

Solutions

Expert Solution

Please give thumbs up, thanks

sample output:  

code:

#include<stdio.h>
#include<stdlib.h>
int main()
{
   int Number[6];
   int i=0;
   int n;
   //ReSTTING ALL NUMBER COUNTS TO 0
   for(i=0; i<6; i++)
   {
       Number[i]=0;
   }
   //while loop for gerenerating values 100 times
   i=1;
   while(i<=100)
   {
       n=rand()%6 +1;
       Number[n-1]+=1;
       i++;
   }
   printf("For 100 times : \n");
   //displaying how many times generated
   for(i=0; i<6; i++)
   {
       printf("%d generated %d times \n",(i+1),Number[i]);
   }
  
   //ReSTTING ALL NUMBER COUNTS TO 0
   for(i=0; i<6; i++)
   {
       Number[i]=0;
   }
   //while loop for gerenerating values 100 times
   i=1;
   while(i<=10000)
   {
       n=rand()%6 +1;
       Number[n-1]+=1;
       i++;
   }
   //displaying how many times generated
   printf("For 10000 times : \n");
   for(i=0; i<6; i++)
   {
       printf("%d generated %d times \n",(i+1),Number[i]);
   }
}


Related Solutions

Write a Java program to simulate the rolling of two dice. The application should use an...
Write a Java program 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. Your application should roll the dice 36,000,000 times. Store the results of each roll...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. 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 2 and 12 being the least frequent sums.] The following table shows the 36 possible combinations of the two dice. Your program should...
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the...
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the total on the dice comes up to be a given number. Ask the user for the number that you are rolling for. To have your program roll two dice, use the rand() function this way: die1 = rand() % 6 + 1; die2 = rand() % 6 + 1; Your program then computes and prints the number of rolls it takes to get the...
Write a program to simulate a calculator. Generate two random numbers (between 1-15) and an ask...
Write a program to simulate a calculator. Generate two random numbers (between 1-15) and an ask the user for an arithmetic operator. Using a switch statement, your program has to perform the arithmetic operation on those two operands depending on what operator the user entered. Ask the user if he/she wants to repeat the calculations and if the answer is yes or YES, keep repeating. If the answer is something else, then stop after the first calculation. c++
in C++, Write a program that asks the user to enter 6 numbers. Use an array...
in C++, Write a program that asks the user to enter 6 numbers. Use an array to store these numbers. Your program should then count the number of odd numbers, the number of even numbers, the negative, and positive numbers. At the end, your program should display all of these counts. Remember that 0 is neither negative or positive, so if a zero is entered it should not be counted as positive or negative. However, 0 is an even number....
1. Let’s use Excel to simulate rolling two dice and finding the rolled sum. • Open...
1. Let’s use Excel to simulate rolling two dice and finding the rolled sum. • Open a new Excel document. • Click on cell A1, then click on the function icon fx and select Math&Trig, then select RANDBETWEEN. • In the dialog box, enter 1 for bottom and enter 6 for top. • After getting the random number in the first cell, click and hold down the mouse button to drag the lower right corner of this first cell, and...
Write a C++ program to generate two random numbers (Rnd1 and Rnd2). These two numbers should...
Write a C++ program to generate two random numbers (Rnd1 and Rnd2). These two numbers should be within a range [100, 500]. If Rnd1 greater than or equals to Rnd2, print out the result of (Rnd1-Rnd2). Otherwise, print out the result of (Rnd2-Rnd1). In all cases, print Rnd1, Rnd2, and the results of subtractions in suitable messages.
Rolling a dice 15 times, find the probability of 6 consecutive rolls have 6 distinct numbers....
Rolling a dice 15 times, find the probability of 6 consecutive rolls have 6 distinct numbers. (i.e. 423123456..., 45612335626..., etc.)
Lets use Excel to simulate rolling two 8-sided dice and finding the rolled sum. • Open...
Lets use Excel to simulate rolling two 8-sided dice and finding the rolled sum. • Open a new Excel document. • Click on cell A1, then click on the function icon fx and select Math&Trig, then select RANDBETWEEN. • In the dialog box, enter 1 for bottom and enter 8 for top. • After getting the random number in the first cell, click and hold down the mouse button to drag the lower right corner of this first cell, and...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the number of rolls of each possible roll value (2 to 12). The number of rolls will be input by the user. Count the rolls of each type and then "draw" a histogram by printing a "*" for each roll of each type. The shape of the histogram will follow the "probability distribution" for large numbers of rolls, i.e., it will show more rolls for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT