Saturday, 4 January 2014

A PROGRAMM TO ROLL A DICE 1000 TIMES AND THEN CHECK HOW MANY TIMES EACH FACE OCCUR

#include<stdio.h>
#include<math.h>
int main()
{
int count,i,x;
int a[1000];
for(i=0;i<1000;i++)
{
a[i]= 1+rand()%6;
}
for(x=1;x<=6;x++)
{
count=0;
for(i=0;i<1000;i++)
{
if(x==a[i])
{
count++;
}
}
printf("Face %d occur %d times\n",x,count);
}
getch();
return 0;
}


Expected output :
Face 1 occur 156 times
Face 2 occur 162 times
Face 3 occur 180 times
Face 4 occur 168 times
Face 5 occur 157 times
Face 6 occur 177 times

No comments:

Post a Comment