PDA

View Full Version : finding max and low values




dukebound85
Oct 8, 2006, 03:33 PM
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



caveman_uk
Oct 8, 2006, 03:59 PM
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.

dukebound85
Oct 8, 2006, 04:08 PM
Sweet Thanks i figured it out!