When all the electrons in a molecule are paired it is diamagnetic and when unpaired electrons are present it is paramagnetic. Considering the filling of electrons in molecular orbitals the e.c. of molecules is
Be2(8)=(σ1s)2,(σ∗1s)2,(σ2s)2,(σ∗2s)2
C2(12)=(σ1s)2,(σ∗1s)2,(σ2s)2,(σ∗2s2)
(π2py)2,(π2pz)2
N2(14)=(σ1s)2,(σ∗ls)2,(σ2s)2,(σ∗2s)2
(π2py)2,(π2pz)2,(σ2px)2
O2(16)=(σ1s)2,(σ∗1s)2,(σ2s)2,(σ∗2s)2
(π2py)2,(σ2px)2
(π2pz)1(π2pz)1
Unpaired electron is present only in O2, so it is paramagnetic.