Thread: Finding max

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    9

    Finding max

    Hi, I have 4 variables whose values can either be some positive number or infinity which I have considered to be 1e+10. My problem is to find out which is the maximum of the four excluding the ones that are infinity. Is there any simple way of doing this without using a really large number of if statements( I haven't tried that either). Any help would be really appreciated. Thanks in Advance. Gaurav.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    without using a really large number of if statements( I haven't tried that either).
    As far as we know you havent tried anything at all, you have not posted any code.

    Why do you think there would be loads of IF statements? Based on your description there would only be 4 if you only have four variables to test, one after the other and no other program requirements are specified. That is not a lot at all.

    You could do it with a loop but altogether would probably be the same amount of code lines more or less so whats the issue?
    Last edited by rogster001; 02-10-2012 at 07:31 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    CLOSED. Replies here - Simple way of finding max

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding the max in row
    By qweqwe in forum C Programming
    Replies: 5
    Last Post: 12-04-2011, 10:46 PM
  2. Finding the mean
    By openwindow in forum C Programming
    Replies: 2
    Last Post: 11-20-2011, 07:34 AM
  3. GPA and finding a job
    By camel-man in forum General Discussions
    Replies: 3
    Last Post: 10-17-2011, 06:18 AM
  4. help finding a bug
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-22-2005, 02:15 AM
  5. finding a job!
    By nima_ranjbar in forum C++ Programming
    Replies: 2
    Last Post: 02-12-2002, 12:00 PM