Guest User

Untitled

a guest
Dec 13th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define MAXCOINS 5
  6. #define THROWS 10000
  7.  
  8. int main(void)
  9. {
  10. int c, t, same, coins, face;
  11. for(coins = 1; coins <= MAXCOINS; coins++) {
  12. same = 0;
  13. for(t = 0; t < THROWS; t++) {
  14. face = rand() & 1;
  15. for(c = 1; c < coins; c++) {
  16. if(face != (rand() & 1))
  17. break;
  18. }
  19. if(c == coins) {
  20. same++;
  21. }
  22. }
  23. printf("Coins=%d Throws=%d Same=%-5d Prob=%f, Guess=%fn",
  24. coins, THROWS, same, (double)same/THROWS, 1.0/pow(2, coins-1));
  25. }
  26. }
Add Comment
Please, Sign In to add comment