← All examples

GCD (Euclid)

Go Algorithms

while + swap

Flowchart (ISO 5807)

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

Source code

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