finding max and low values

Discussion in 'Mac Programming' started by dukebound85, Oct 8, 2006.

  1. dukebound85 macrumors P6

    dukebound85

    Joined:
    Jul 17, 2005
    Location:
    5045 feet above sea level
    #1
    so i got the avg program to work but now have a hard time finding the max and min of values that i enter. i am trying to write this program for data mangement so this would be a nice feature.

    my for loop pretty much asks for how many numbers then it calculates the avg at this point. any idea about how to determine the max and min value

    say i entered 6,3,10

    how do i get it to print out the low is 3 and high is 10?

    thanks

    oh yea this is in c
     
  2. caveman_uk Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    Two variables, one called max and the other min. Set them both to the value of the first number. As you interate through your for loop use a couple of if statements to check if the current number is higher or lower than the current max/min. If so update max and min as appropriate. At the end of the loop you have your max and min values.
     
  3. dukebound85 thread starter macrumors P6

    dukebound85

    Joined:
    Jul 17, 2005
    Location:
    5045 feet above sea level

Share This Page