Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void main()
- {
- srand(time(NULL));
- int rand1, rand2, yes=0, n=0, boxes[3][2]={{1,1} , {2,2} , {1,2}}; // 1- golden coin;
- while (n<RAND_MAX)
- {
- do
- {
- rand1=rand()%3;
- rand2=rand()%2;
- }
- while (boxes[rand1][rand2]!=1);
- if (rand2==0 && boxes[rand1][1]==1) yes++;
- else if (rand2==1 && boxes[rand1][0]==1) yes++;
- n++;
- }
- printf ("Probability: %lf\n\n\n", yes/(double)n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement