Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads.
For example, given 2 coins the possible outcomes are:
HH HT TH TT
where H and T are heads and tails. There are 2 outcomes (HT
and TH
) that are half as many heads as the number of coins. There are a total of 4 outcomes, so the probability is 2/4 = 0.5.
This is simpler than it looks.
Test cases:
2 -> 0.5
4 -> 0.375
6 -> 0.3125
8 -> 0.2734375