Prompt D meson and non-prompt J/ψ yields are studied as a function of the multiplicity of charged particles produced in inelastic proton-proton collisions at a centre-of-mass energy of \( \sqrt{s}=7 \) TeV. The results are reported as a ratio between yields in a given multiplicity interval normalised to the multiplicity-integrated ones (relative yields). They are shown as a function of the multiplicity of charged particles normalised to the average value for inelastic collisions (relative charged-particle multiplicity). D0, D+ and D*+ mesons are measured in five p T intervals from 1 GeV/c to 20 GeV/c and for |y| <0.5 via their hadronic decays. The D-meson relative yield is found to increase with increasing charged-particle multiplicity. For events with multiplicity six times higher than the average multiplicity of inelastic collisions, a yield enhancement of a factor about 15 relative to the multiplicity-integrated yield in inelastic collisions is observed. The yield enhancement is independent of transverse