N-body simulations of secondary infall. I - Formation of mass profile in galactic halos