To get the molecular formula, you must either know the molecular mass or do an experiment to find it.
Example
An unknown compound contains #"85.63 % C"# and #"14.37 % H"#. Its experimental molar mass is #"56 g/mol"#. What is its molecular formula?
Solution
Assume we have #"100 g"# of the compound. Then we have #"85.63 g of C"# and #"14.37 g of H"#.
#"Moles of C" = 85.63 color(red)(cancel(color(black)("g C"))) × "1 mol C"/(12.01color(red)(cancel(color(black)("g C")))) = "7.130 mol C"#
#"Moles of H" = 14.37 color(red)(cancel(color(black)("g H"))) × "1 mol H"/(1.008 color(red)(cancel(color(black)("g H")))) = "14.26 mol H"#
#"Moles of C"/"Moles of H" = (7.130 color(red)(cancel(color(black)("mol"))))/(14.26 color(red)(cancel(color(black)("mol")))) = 1/2.000 ≈ 1/2#
The empirical formula is #"CH"_2#.
The empirical formula is the simplest formula of a compound.
The actual formula is an integral multiple of the empirical formula.
If the empirical formula is #"CH"_2#, the actual formula is #("CH"_2)_n# or #C_nH_(2n)#, where #n = 1, 2, 3, …# .
Our job is to determine the value of #n#.
The empirical formula mass of #"CH"_2# is #"14.03 u"#. The molecular mass of #"56 u"# must be some multiple of this number.
#n = (56 color(red)(cancel(color(black)("u"))))/(14.03 color(red)(cancel(color(black)("u")))) = 4.0 ≈ 4#
∴ The molecular formula is #C_nH_(2n) = "C"_4"H"_8#.