Think of it this way:
First, you need to take the hour and do a modulo 12 on it, because there aren't 24 hours on a clock.
Next, every minute, the minute hand moves by 6 degrees (360/60).
Now, the hour hand does a complete rotation in 12 hours, that would be 30 degrees per hour (360 degrees / 12 hours)
Of course, as the minute hand rotates beyond H:00, the hour hand keeps advancing, so we need to account for that. We know it takes 60 minutes for the hour hand to advance by 30 degrees, so the correction is (fraction of an hour) * 30 degrees.
So the angle between 12 o'clock and the position of the hour hand (Ha) is:
Hour = Hour % 12 -> handle values past noon
Ha = 30*Hour -> position of the hour hand without correction
Ha = Ha + (Minute / 60 * 30 degrees) -> correction for the position of the hour hand
And the angle between noon and the minute hand (Ma) is:
Ma = 360 degrees / 60 minutes * Minute
And so the angle between the two hands is:
Abs(Ha - Ma)
For instance, for 14h20:
Hour = 14 % 12 = 2
Ha = 30 * 2 = 60 (uncorrected)
Ha = Ha + (20 / 60 * 30) = 70°
Ma = 360 / 60 * 20 = 120°
Angle between the two = 50°
Whenever you have a problem like this one, try to draw it on the board, and pick easy values, for instance 6:30, which is obviously not 0°, but half of the angle that represents 5 minutes, and you'll end up figuring it out pretty quickly.