H2X: $\text{Element/ Ion}\ \ \ \ \ \ \ \text{H}\ \ \ \ \ \ \text{X}\\ \ \ \ \text{Valency}\ \ \ \ \ \ \ \ \ \ \ \ \ \ 1\ \ \ \ \ \ 2$
To stabilize the compound with hydrogen, two atoms of X are required. Therefore, the valency of X in this compound will be two.
CX2:
$\text{Element/ Ion}\ \ \ \ \ \ \ \text{C}\ \ \ \ \ \ \text{X}\\ \ \ \ \text{Valency}\ \ \ \ \ \ \ \ \ \ \ \ \ \ 4\ \ \ \ \ \ 2$
To stabilize the compound with hydrogen, two atoms of X are required. Thus, the valency of X in this compound is two.
XO2:
$\text{Element/ Ion}\ \ \ \ \ \ \ \text{X}\ \ \ \ \ \ \ \ \ \ \text{O}\\ \ \ \ \text{Valency}\ \ \ \ \ \ \ \ \ \ \ \ \ \ 4\ \ \ \ \ \ -2$
To stabilize this compound with oxygen, four atoms of X are required. Thus the valency of X in this compound if four.
XO3:
$\text{Element/ Ion}\ \ \ \ \ \ \ \text{X}\ \ \ \ \ \ \ \ \ \ \text{O}\\ \ \ \ \text{Valency}\ \ \ \ \ \ \ \ \ \ \ \ \ \ 6\ \ \ \ \ \ -2$
To stabilize this compound with oxygen, six atoms of X are required. Thus, the valency of X in this compound is six.