Flowchart: greatest common divisor, Euclid's algorithm
Until b is 0, replace a with b and b with the remainder of a divided by b. Then print a as the greatest common divisor.
Steps
- Start, then read two numbers a and b.
- Decide whether b is 0.
- If not, store the remainder of a divided by b in r.
- Put b into a and r into b, then go back to the decision.
- When b is 0, a is the greatest common divisor. Print it and end.
Good to know
- Assume a and b are integers greater than 0.
- Example: for a=12 and b=18 the pair changes (12,18), (18,12), (12,6), (6,0) and the answer is 6.
Drawing happens in this browser only. Your text is never sent to a server. Symbol rules differ a little between textbooks, so check them against your course before you hand in.