An algorithm for processing mass spectra of gases exhaled by patients has been proposed in the paper. The mass spectra are recorded on the MS7-200 quadrupole mass spectrometer, with electronic ionization and with direct capillary injection of the sample. The algorithm is based on transforming an array of spectra (not less than 10) in the space of principal components. The probability of a disease is determined through the Euclidean distance of the patient's coordinates from the centroid. Testing of the algorithm was carried out on the data of mass spectra of gases exhaled by cancer patients. The proposed procedure has several advantages over traditional laboratory methods. The algorithm uses the multidimensional probability density of the distribution of the parameters of the exhaled gases of control groups and the patient being tested and allows to compile an overall picture of the patient's probable diseases in a short time.