Solution:
Concept: A gram atom is one mole of atoms of an element: gram atoms = mass ÷ atomic mass. The simplest ratio of gram atoms gives the simplest formula.
Step 1 — (a) Gram atoms of magnesium.
We divide 18 g by the atomic mass of magnesium, 24.
gram atoms of Mg=2418=0.75
Step 2 — (b) Gram atoms of nitrogen.
We divide 7 g by the atomic mass of nitrogen, 14.
gram atoms of N=147=0.5
Step 3 — (c) Find the simple ratio.
Dividing both by 0.25 makes them whole numbers.
Mg:N=0.75:0.5=3:2
So the simplest formula is Mg₃N₂ (magnesium nitride), which fits the valencies Mg²⁺ and N³⁻.

Watch out: Dividing by the smaller value (0.5) gives 1.5 : 1, which is not whole; multiply by 2 to get 3 : 2.
Therefore, (a) 0.75 gram atom of magnesium; (b) 0.5 gram atom of nitrogen; (c) Mg : N = 3 : 2, so the formula is Mg₃N₂.