S SmartDocs
Series: computer science c 13 lines · Updated 2026-02-03

gcd.c

computer_science/materials/chapter03/gcd.c

#include <stdio.h>

int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {
    int a = 48, b = 18;
    printf("GCD of %d and %d is %d\n", a, b, gcd(a, b));
    return 0;
}

Related articles