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...
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...
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...
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.)
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...
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
*****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...
In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT