The key to understanding this problem is realizing that the volume of each gas is directly proportional to the number of moles of each gas.

When the hydrocarbon undergoes combustion, all of the carbon appears as #CO_2# in the products, so in this example we see that the number of carbon atoms in the hydrocarbon must be 2, because the volume of #CO_2# is twice that of the original hydrocarbon.

Likewise, all of the hydrogen appears as #H_2O# in the products. This means that the volume of #O_2# required to carry out the combustion must be greater than the volume of #CO_2# produced (because some of the #O_2# is needed to produce #H_2O#).

In this problem, however, the volume of #O_2# consumed (15 #cm^3#) is less than the volume of #CO_2# produced, which cannot be the case if the hydrocarbon is composed only of carbon and hydrogen.

The most likely case is that the data in the problem are incorrect.

The balanced equation for combustion of hydrocarbon #C_xH_y# is

#C_xH_y + (x+y/4)O_2 harr x CO_2 + (y/2)H_2O#

If the volume of #O_2# consumed were actually 35 #cm^3#, then we would say that because the moles of #O_2# consumed is 3.5 times higher than the moles of hydrocarbon produced, and

#3.5=x+y/4#

We already know that #x=2# from the volume of #CO_2# produced. Therefore, #y=6# and the formula of the hydrocarbon would have been #C_2H_6#.