Skip to content

LCM

C least common multiple

Flowchart (ISO 5807)

YesNoStartInput a, bg = a, t = bt ≠ 0r = g mod tg = tt = rReturn a / g·bEndFigure 1 — lcm

Source code

C
int lcm(int a, int b) {
    int g = a, t = b;
    while (t != 0) {
        int r = g % t;
        g = t;
        t = r;
    }
    return a / g * b;
}

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

Language
C
Constructs
least common multiple
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples