How are heavy elements formed?
Carbon and Neon are produced by fusion reactions in stars. Uranium is formed by neutron capture in a supernova explosion.
Lighter atomic nuclei are lighter that the sum of their components. For example a Carbon-12 nucleus has 6 protons and 6 neutrons. The mass of a Carbon-12 nucleus is less that the masses of 6 free protons plus 6 free neutrons. This is called the mass defect. Energy has to be provided to split up a lighter elements.
Nuclear fusion creates energy by fusing lighter nuclei to make heavier nuclei the energy corresponding to the mass defect is call binding energy and is released by the fusion process.
Fusing Hydrogen into Helium generates the most energy. Fusing nuclei to make heavier elements releases less energy. This process works until Iron is reached. Creating elements heavier than Iron requires additional energy. In fact energy is released when nuclei heavier than Iron are split.
Carbon and Neon are produced by fusion in larger stars which have used up their supply of lighter elements. Heavy elements such as Uranium can't be produced by fusion as too much additional energy is required.
When a star explodes as a supernova, vast numbers of fast neutrons are released. These neutrons are captured by nuclei. Some of the neutrons undergo beta decay in the nucleus to form protons. This is the process by which elements heavier than Iron, including Uranium, are created.