Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2014
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void main()
  6. {
  7. srand(time(NULL));
  8. int rand1, rand2, yes=0, n=0, boxes[3][2]={{1,1} , {2,2} , {1,2}}; // 1- golden coin;
  9.  
  10. while (n<RAND_MAX)
  11. {
  12. do
  13. {
  14. rand1=rand()%3;
  15. rand2=rand()%2;
  16. }
  17. while (boxes[rand1][rand2]!=1);
  18.  
  19. if (rand2==0 && boxes[rand1][1]==1) yes++;
  20. else if (rand2==1 && boxes[rand1][0]==1) yes++;
  21.  
  22. n++;
  23. }
  24.  
  25. printf ("Probability: %lf\n\n\n", yes/(double)n);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement