In: Computer Science
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.
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]);
}
}