The production cross section of prompt Λ+c charm baryons was measured with the ALICE detector at the LHC at midrapidity in proton-proton (pp) and proton-lead (p–Pb) collisions at a center-of-mass energy per nucleon pair of √sNN=5.02TeV. The Λ+c and ¯¯¯Λ−c baryons were reconstructed in the hadronic decay channels Λ+c→pK−π+ and Λ+c→pK0S and respective charge conjugates. The measured differential cross sections as a function of transverse momentum (pT) and the pT-integrated Λ+c production cross section in pp and in p–Pb collisions are presented. The Λ+c nuclear modification factor (RpPb), calculated from the cross sections in pp and in p–Pb collisions, is presented and compared with the RpPb of D mesons. The Λ+c/D0 ratio is also presented and compared with the light-flavor baryon-to-meson ratios p/π and Λ/K0S, and measurements from other LHC experiments. The results are compared to predictions from model calculations and Monte Carlo event generators.