Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Lmc program

  1. Oct 11, 2008 #1

    i'm trying to make an lmc that gives oupts the 2 largest values from 3 inputs.

    i know how to find out the largest from 2 values but cant think of how to get the largest from 3 inputs.

    any help would be appreciated

  2. jcsd
  3. Oct 11, 2008 #2
    I have no idea what an "lmc" program is. Could you elaborate on that?

    Regardless, returning the largest pair of three given values is trivial. I'll give you a hint how to write a function that will return the largest single value from three values; writing a function to return the largest two values should then be easy for you. I'll write it in C++ for the sake of argument.

    Code (Text):

    double max(const double& a, const double& b, const double&c)
       double maxTempVariable = a;

       if (b > maxTempVariable)
          maxTempVariable = b;
       if (c > maxTempVariable)
          maxTempVariable = c;

       return maxTempVariable;
    If you're interested in applying this to more general objects, classes together with appropriately overloaded relational operators is the ways to go.
  4. Oct 11, 2008 #3
    have a look at this.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook