#include
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
typedef int BOOL;
#define GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
BOOL roll_dice_is_snake_eyes()
{
int d1,d2;
d1=GetRandom( 1, 6 );
d2=GetRandom( 1, 6 );
if(d1 == 1 && d2 == 1)
return TRUE;
return FALSE;
}
#define TRIES (1000L*1000L*1000L)
int main(int argc, char* argv[])
{
long i, sum=0;
printf("The probability that 2 dice will land snake eyes\n");
/* initialize/seed random number generator */
srand( (unsigned)time( NULL ) );
for(i=0; i
{
if(roll_dice_is_snake_eyes())
sum++;
}
printf("\nIn %ld tries, dice came up snake eyes %ld times.\n",TRIES,sum);
printf("The probability is thus: %0.9f\n", (double)(sum) / (double)(TRIES));
getch();
return 0;
}
is there a certain way to do this i thought you had to start with main or something like that. i need like step by step instructions. i have never done this before
2007-12-02
06:23:17
·
1 answers
·
asked by
eronau
2