The production of the X(3872) is studied in pp collisions at root s = 7TeV, using decays to J/psi pi(+)pi(-), where the J/psi decays to two muons. The data were recorded by the CMS experiment and correspond to an integrated luminosity of 4.8 fb(-1). The measurements are performed in a kinematic range in which the X(3872) candidates have a transverse momentum 10 < p(T) < 50 GeV and rapidity vertical bar y vertical bar < 1.2. The ratio of the X(3872) and (2S) cross sections times their branching fractions into J/psi pi(+)pi(-) is measured as a function of p T. In addition, the fraction of X(3872) originating from B decays is determined. From these measurements the prompt X(3872) differential cross section times branching fraction as a function of p(T) is extracted. The pi(+)pi(-) mass spectrum of the J/psi pi(+)pi(-) system in the X(3872) decays is also investigated.