That's the correct formula.
When you're asked the probability of r occurences out of n attempts, you use the formula:
nCr x p^r x q^ n-r
Where nCr is the number of combinations (the boy being born first, second, or last; the heads landing on the first 3 throws, last 3 throws, first-second-fourth throws, etc). p^r is the probability of your favorable outcomes and the number of times you want them to occur. q^(n-r) is the probability of your unfavorable outcome raised to the number of times they should occur.
in your first example, the setup is:
3C1 x (1/2)^1 x (1/2)^2 = 3/8
in your second example, the setup is
5C2 x (1/2)^3 x (1/2)^2 = 10/32 = 5/16
these are simple examples where the probability of unfavorable and favorable outcomes is the same. The formula ALSO works when they are different, say if you had to calculate the chance it will rain 3 out of 7 days if the chance of rain on each day were 40%:
7C3 x (0.4)^3 x (0.6)^4