I guess you don't mean "what is the worst possible grade I can get for the semester", as that would simply mean a result of 0 in the final exam.


Assuming that you know what Final Grade is wanted (and what the lowest value is to get that grade), and you want to know the "minimum score" for the final exam to get it, you can simply re-arrange the formula:

Final Grade = (1stQuarter * 40%) + (2nd Quarter * 40%) + (Final Exam * 20%)
=>
Final Grade - ((1stQuarter * 40%) + (2nd Quarter * 40%)) = (Final Exam * 20%)
=>
(Final Exam * 20%) = Final Grade - ((1stQuarter * 40%) + (2nd Quarter * 40%))
=>
Final Exam = (Final Grade - ((1stQuarter * 40%) + (2nd Quarter * 40%))) / 20%