I am 18 and I have mild acne on my forehead and back for 3 years. I also have very flaky dandruff on my scalp. Kindly suggest a medication.

Acne. If you have acne in multiple areas you may need oral antibiotic therapy, there are other treatment options available also, Better consult a Dermatologist. Common at this age, stress can make it worse.
Benzoyl peroxide 10% I would try a 10% benzoyl perozide wash or creme for starters on the face and back for one month, apply twice a day. Your skin may get pink and peel a bit, then your new acne should decrease in the second month. For your dandruff ,use Selsun Blue with Selenium Sulfide 2.5% active ingredient twice a week to soften up and resolve the dandruff flakes. Good luck!