Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dukebound85

macrumors Core
Original poster
Jul 17, 2005
19,160
4,152
5045 feet above sea level
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

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.