Formation of Compound
We get chemical formula of molecule by writing valence of 1st atom in front of 2nd atom and valence of 2nd atom in front of 1st atom.
Example: valence of carbon is 4 and oxygen is 2, write 4 in front of O and 2 in front of C in subscripts as shown below.
as we see, both valences are multiple of two so divide it by two to get CO2 formula.
Na+ + CO3-2 ---> Na2CO3
Al+3 + SO4-2 ---> Al2(SO4)3
Mg+2 + N-3 ---> Mg3N2