Greatest Common Divisor (GCD)

int gcd( int a, int b ) {
    return b == 0 ? a : gcd( b, a % b );
}

int gcdOfList( int *list, int num ) {
    int result = list[0];
    for( int i = 1; i < num; ++i ) {
        result = gcd( result, list[i] );
    }
    
    return result;
}

Leave a Reply

Your email address will not be published. Required fields are marked *