Alkane chemical formulae

Question Q2.5.4

Straight-chain alkanes are hydrocarbons with the general stoichiometric formula $\mathrm{C}_n\mathrm{H}_{2n+2}$ in which the carbon atoms form a simple chain: for example, butane, $\mathrm{C_4H_{10}}$ has the structural formula which may be depicted $\mathrm{H_3CCH_2CH_2CH_3}$. Write a program to output the structural formula of such an alkane, given its stoichiometry (assume $n>1$). For example, given stoich='C8H18', the output should be:

H3C-CH2-CH2-CH2-CH2-CH2-CH2-CH3

Solution Q2.5.4