Hi there,

Recently I got a book on "Algorithms in C". It covers a lot of algorithms and implements them in C examples.

There are some exercises in it. One of them is to calculate the gcd (Greatest Common Divisor, Euclid) of three numbers. I have the implementation of two numbers, that's easy.

I was thinking how to do it. Is it the best way to calculate the gcd of all combinations and then take the lowest of those as the gcd of all three? Or can this be done more efficiently?

Example:

Code:

a = 12
b = 28
c = 18
GCD
a,b: 4
b,c: 2
a,c: 6
So the gcd of a,b,c is 2

Thanks