Skip to content

GCD (recursion)

Python Euclid recursion

Flowchart (ISO 5807)

YesNoStartInput a, bb = 0Return aEndReturn gcd(b, a mod b)EndFigure 1 — gcd

Source code

Python
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
Euclid recursion
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples