Flowers, nuts, seeds and fruits are the “crowning glories” of a tree. Each has a role to play in the propagation of the species, regardless of how fleeting its time connected to the tree itself may be. Seeds may be enclosed within a fruit or nut (angiosperms, such as an acorn or a pear), or unenclosed (gymnosperms such as conifers and gingkos). But any tree that fails to produce seeds is incapable of reproducing itself on its own.
The flower has the job of attracting pollinators; our enjoyment of its beauty and/or scent is merely an unintended consequence. A tree does not think, I would like to produce something beautiful today, it just does