Skip to content

GCD (Euclid)

Go while + swap

Same task in: PascalPHPRust

Flowchart (ISO 5807)

YesNoStartInput a, bb ≠ 0a, b = b, a%bReturn aEndFigure 1 — gcd

Source code

Go
func gcd(a, b int) int {
    for b != 0 {
        a, b = b, a%b
    }
    return a
}

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

Language
Go
Constructs
while + swap
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples