If 12 gram of carbon has x atoms, then the number of atoms in 12 grams of magnesium will be:
Atomic weight of carbon = 12g
One atom of carbon weighs 12g
Atomic weight of magnesium is 24 g
Hence, 1/2 atom of magnesium weighs 12g