Effect of density on the equilibrium charge distribution of carbon and oxygen ions