The two examples are
a) elements: Carbon and hydrogen : C(s) and H2(g)
b) compounds: CO2 and CH4
The reaction is
A + B ----> C + D
We know that from law of conservation of mass
Mass of reactants reacted = mass or products formed
Mass of A = 22
Mass of B = 14
Mass of C = 9
Mass of D = (A + B) - (C) = 27 g