Return to Snippet

Revision: 63598
at May 21, 2013 16:36 by zaxbbun


Updated Code
// solution one
//
template <class T>
T max(T a, T b){
    return (a + b + abs(a - b)) / 2;
}


// solution two
//
template <class T>
T max(T a, T b){
    T num[2] = [a, b];
    return num[a < b];
}

Revision: 63597
at May 21, 2013 16:35 by zaxbbun


Updated Code
// solution one
//
template <class T>
T max(T a, T b){
    return (a + b + abs(a - b)) / 2;
}

// solution two
//
template <class T>
T max(T a, T b){
    T num[2] = [a, b];
    return num[a < b];
}

Revision: 63596
at May 21, 2013 16:22 by zaxbbun


Initial Code
// solution one
//
template <class Type>
Type max(Type a, Type b){
    return (a + b + abs(a - b)) / 2;
}

// solution two
//
template <class Type>
Type max(Type a, Type b){
    Type num[2] = [a, b];
    return num[a < b];
}

Initial URL

                                

Initial Description
max: compare two numbers withou using [if, switch, :?]

Initial Title
max: compare two numbers withou using [if, switch, :?]

Initial Tags

                                

Initial Language
C