Using the direct formula for equal cost and selling prices, the profit percentage is 100 multiplied by the difference of the quantities divided by the smaller quantity. The calculation is 100 multiplied by the quantity 21 minus 18 divided by 18. This evaluates to 300 divided by 18, resulting in a gain of 16 percent.