


The GCD of three or more numbers equals the product of the prime factors common to all the numbers, but it can also be calculated by repeatedly taking the GCDs of pairs of numbers.gcd(a, b, c) = gcd(a, gcd(b, c))= gcd(gcd(a, b), c)= gcd(gcd(a, c), b)For an array of elements, we do the following. We will also check for the result if the result at any step becomes 1 we will just return the 1 as gcd(1,x)=1.result = arr0For i = 1 to n-1result = GCD(result, arri)Below is the implementation of the above idea.