I can't decide whether I can help without spoonfeeding or not.
This is what you're trying to do: Greatest common divisor - Wikipedia, the free encyclopedia
You have to write Euclid's algorithm at...