I'm new to coding, and stack Overflow. I just wanted to see what's the BEST approach to solve this problem.
My approach// run a for loop that assigns the number to a variable if it's dividing all elements. Problem is I can't represent the for loop properly. Is my approach wrong? Would you use a dictionary instead? I just need the approach & maybe the loop. THANK YOU!
the greatest common divisor (GCD), also called highest common factor(HCF) of N numbers is the largest positive integer that divides all numbers without giving a remainder. Write an algorithm to determine the GCD of N positive integers.
func generalizedGCD(num:INT, arr:[Int])->Int
num- an integer representing the number of positive integers(N), arr - list of positive integers
input/ num = 5, arr = [2,4,6,8,10]
Output/ 2
input/ num = 5, arr = [2,3,4,5,6]
output/ 1