Study of the ultrahigh-energy primary-cosmic-ray composition with the MACRO experiment