Max Value Function

Max Value

Implement a function named max_float that takes 3 floats and returns the largest among them.

float max_float(float a, float b, float c);

Answer

Using if statements

float max_float(float a, float b, float c)
{
    if (a > b && a > c)
    {
        return a;
    }
    else if (b > a && b > c)
    {
        return b;
    }
    else
    {
        return c;
    }
}

Using ternary operator

float max_float(float a, float b, float c)
{
    return (a > b ? (a > c ? a : c) : (b > c ? b : c));
}
Questions