First you need to find the molar mass of your molecule, in this case glucose. To do this find the molar mass of Carbon, which is 12 g per mole multiply it by how many carbons in glucose, which is 6. 12*6 = 72. So we have 76 g of carbon.
We need to find the molar mass of Hydrogen now, this is 1g per mole. We have 12 hydrogens. 12*1=12 So we have 12 g of hydrogen.
Next find the molar mass of Oxygen. This is 16g per mole. We have 6 oxygens. 6*16 = 96. So we have 96g of Oxygen.
Now we add up all three to get the molar mass. 72 + 12 + 96 = 180 g of glucose or C6H12O6
So to find percent by mass take the grams of carbon you have and divide it by the total grams of the molecule you have.
In this case 72/180 = 0.4 take this and multiply by 100 and we are given our percent mass which is 40 %.