The probability of getting a heads or tails on the first flip is 0.5. This can be written as P(H) = 0.5, where P is the probability notation and H is the event. Likewise with tails: P(T) = 0.5
The probability of getting a heads, then another heads is 0.25, since we can have 4 possible outcomes on the second flip. That is: (H,H) (H,T) (T,H) (T,T). Since on the second flip the probability of getting a heads or a tails is also 0.5, we can multiply it by the first flip.
Therefore, P(H,H) = 0.5 * 0.5
= 0.25
Likewise, P(H,T) = 0.5 * 0.5
= 0.25
From this, we can see that no matter the combination the probability of that occurring is the same. Also we also notice that the probability can be generalised. The P(H,H) = 0.5
2; P(H,H,H) = 0.5
3, etc...
Therefore on the ninth flip, P(H,H,H,H,H,H,H,H,H) = 0.5
9
= 0.001953125
This is the same for all events on the ninth flip, no matter how many heads or tails you get.
I have a pdf to demonstrate this:
https://www.dropbox.com/s/xagjmqr0o4937xf/Coin%20Probability.pdf?dl=0
Also, you have to seed the rand function, otherwise it'll output the same result every time.
http://www.cplusplus.com/reference/cstdlib/srand/