The primary function of leaves is to collect sunlight as the energy source to drive photosynthesis. Photosynthesis is the process that occurs in plant cells. The chlorophyll (green pigment located within the chloroplasts) is what captures the sunlight energy. This energy is used to transform six carbon dioxide molecules plus six water molecules into one glucose molecule and six oxygen molecules. This chemical formula can be seen via this hyperlink.
The majority of the carbon dioxide used in photosynthesis comes from the cellular respiration done by living things. The gas enters the plant via small pores that are located on the bottom of the leaf called stomata. It is also through the stomata that the water and oxygen exit.
The water that is used during photosynthsis is absorbed by the roots from the ground.