typestar

GCD in C

Euclid's algorithm, still the shortest correct answer after two thousand years.

int gcd(int a, int b) {
    while (b != 0) {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
83
Tokens
38
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 25 seconds.

Type this snippet

Step 3 of 7 in Functions, step 17 of 35 in Language basics.

← Previous Next →

GCD in other languages