We introduce a new technique for following the formation and evolution of galaxies in cosmological N-body simulations. Dissipationless simulations are used to track the formation and merging of dark matter haloes as a function of redshift. Simple prescriptions, taken directly from semi-analytic models of galaxy formation, are adopted for gas cooling, star formation, supernova feedback and the merging of galaxies within the haloes. This scheme enables us to explore the clustering properties of galaxies, and to investigate how selection by luminosity, colour or type influences the results. In this paper we study the properties of the galaxy distribution at z=0. These include B- and K-band luminosity functions, two-point correlation functions, pairwise peculiar velocities, cluster mass-to-light ratios, B-V colours, and star formation rates. We focus on two variants of a cold dark matter (CDM) cosmology: a high-density (Ω =1) model with shape-parameter Γ =0.21 (τ CDM), and a low-density model with Ω =0.3 and Λ =0.7 (Λ CDM). Both models are normalized to reproduce the I-band Tully--Fisher relation of Giovanelli et al. near a circular velocity of 220 km s-1. Our results depend strongly both on this normalization and on the adopted prescriptions for star formation and feedback. Very different assumptions are required to obtain an acceptable model in the two cases. For τ CDM, efficient feedback is required to suppress the growth of galaxies, particularly in low-mass field haloes. Without it, there are too many galaxies and the correlation function exhibits a strong turnover on scales below 1 Mpc. For Λ CDM, feedback must be weaker, otherwise too few L* galaxies are produced and the correlation function is too steep. Although neither model is perfect, both come close to reproducing most of the data. Given the uncertainties in modelling some of the critical physical processes, we conclude that it is not yet possible to draw firm conclusions about the values of cosmological parameters from studies of this kind. Further observational work on global star formation and feedback effects is required to narrow the range of possibilities.