Generally the rule is that the future (will, won't) can't be used in an IF clause.
IF clauses use the present tense to discuss the condition under which future events will or won't happen. So "If the teacher doesn't come, we won't have the exam" is the correct form.
(Sometimes "will"/"won't" is permitted if the meaning is "is/isn't willing to". If "the teacher won't come" was intended to mean "the teacher refuses to come" then "If the teacher won't come" would be acceptable wording.)
From the British Council website:
We use the first conditional when we talk about real and possible situations.
- I’ll go shopping on the way home if I have time.
- If it’s a nice day tomorrow, we’ll go to the beach.
- If Arsenal win, they’ll be top of the league.
In first conditional sentences, the structure is usually if + present simple and will + infinitive. It’s not important which clause comes first.