AGB stars in the Magellanic Clouds. I. The C/M ratio