Molar mass of carbon = 12 g/mole
Number of moles of carbon in 6 g = 6/12 = 0.5
Number of atoms in 1 mole of carbon = 6.02 x 1023
Number of atoms in 0.5 moles of carbon = 6.02 x 1023 x 0.5 = 3.01 x 1023
Now, mass of 6.02 x 1023 atoms of magnesium = 24 g
Mass of 3.01 x 1023 atoms of magnesium = (24/6.02 x 1023 ) x 3.01 x 1023
= 12 g
Hence, 12 g grams of Magnesium will have the same number of atoms as 6 grams of Carbon