Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define MAXCOINS 5
- #define THROWS 10000
- int main(void)
- {
- int c, t, same, coins, face;
- for(coins = 1; coins <= MAXCOINS; coins++) {
- same = 0;
- for(t = 0; t < THROWS; t++) {
- face = rand() & 1;
- for(c = 1; c < coins; c++) {
- if(face != (rand() & 1))
- break;
- }
- if(c == coins) {
- same++;
- }
- }
- printf("Coins=%d Throws=%d Same=%-5d Prob=%f, Guess=%fn",
- coins, THROWS, same, (double)same/THROWS, 1.0/pow(2, coins-1));
- }
- }
Add Comment
Please, Sign In to add comment