As a flower forms, each cell must be assigned a role. During development, the concentration of different proteins in each cell determines whether they will become a petal cell, part of the stamen, or something else.
An entire flower can be produced from just three genes. "A" proteins alone produce a sepal cell, while A and "B" together make petal cells. "C" proteins control the carpels and the stamen: C alone produces carpel cells, while C and B together form stamen cells.
There is one flower that does not follow the classic ABC layout. It bewildered botanists for decades, but it turns out to be the exception that proves the rule.