To calculate percentage composition we will take the example CO2 it stands for Carbon-Di-Oxide. It is the composition of Carbon and Oxygen. We have one carbon and its weight is 12.01 and 2 oxygen. So, we will multiply 2 with 16.00 which is the weight of the oxygen.
C - 1* 12.01=12.01
O - 2* 16.00=32.00
44.01 g CO2
This is the total weight of CO2. Now, to know the percent composition of Carbon and Oxygen .We will divide their weight with the total weight of CO2.
% C = 12.01/44.01 = 0.2729= 27.29% (we will divide 0.2729 with 100 to take the percentage).
So , % C in CO2 is 27.29%
% O = 32.00/44.01 =0.7271 =72.71 %O in CO2.