An x-ray computed tomography (CT) simulator based on the Monte Carlo N-particle radiation transport computer code (MCNP4C) was developed for simulation of both fan- and cone-beam CT scanners. A user-friendly interface running under Matlab 6.5.1 creates the scanner geometry at different views as MCNP4C's input file. The full simulation of x-ray tube, phantom and detectors with single-slice, multi-slice and flat detector configurations was considered. The simulator was validated through comparison with experimental measurements of different nonuniform phantoms with varying sizes on both a clinical and a small-animal CT scanner. There is good agreement between the simulated and measured projections and reconstructed images. Thereafter, the effects of bow-tie filter, phantom size and septa length on scatter distribution in fan-beam CT were studied in detail. The relative difference between detected total, primary and scatter photons for septa length varying between 0 and 95 mm is 11.2%, 1.9% and 84.1%, respectively, whereas the scatter-to-primary ratio decreases by 83.8%. The developed simulator is a powerful tool for evaluating the effect of physical, geometrical and other design parameters on scanner performance and image quality in addition to offering a versatile tool for investigating potential artefacts and correction schemes when using CT-based attenuation correction on dual-modality PET/CT units.