Many of the most beautiful cultivated flowers have 5 or 4 petals, though another big plant category, the monocots, often have three petals (or multiples of three).
Petals are modified leaves that surround the reproductive parts of flower, and have various functions and purposes depending on the type of plant. In general, petals operate to protect some parts of the flower and attract/repel specific pollinators.
Flower petals show a great variety of patterns. Petals of different species of plants vary greatly in color or color pattern, both in visible light and in ultraviolet. Such patterns often function as guides to pollinators.
Various color traits are used by different petals, helping attract pollinators that have poor smelling abilities, or that only come out at certain parts of the day. Some flowers are able to change the color of their petals as a signal to mutual pollinators to approach or keep away.
Furthermore, the shape and size of the flower/petals is important in selecting the type of pollinators they need. Collectively the scent, color and shape of petals all play a role in attracting/repelling specific pollinators and providing suitable conditions for pollinating.
Information source: Wikipedia