Subscribe Us

Highest Common Factor

Highest Common Factor In C


int HCF(int input1, input2[]){
    int result = 0;
        for (int element: input2){
            result = gcd(result, element);
            if(result == 1)
            {
               return 1;
            }
        }
        return result;
}

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

Post a Comment

0 Comments