# Euclid’s Algorithm C code

Euclid’s algorithm calculates the GCD (Greatest Common Divisor) for two numbers *a* and *b*. The following C program uses recursion to get the GCD.

Loading...

The code is also available on GitHub.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> int euclid(int a, int b) { if (b == 0) { return a; } else { return euclid(b, a % b); } } int main(int argc, char* argv[]) { int a = 30, b = 21; printf("GCD is %d\n", euclid(a, b)); return 0; } |

Loading...