207.179.135.18 writes:
Hello everyone. i need some help with the above subject.How do i write a program to find the smallest and largest value in an unordered array I randomly generate 25 numbers between 1 and 100, store them in an array and search for the largest and smallest. of integers?
Can anybody help me here, please?
THank you:)
Jo
152.202.103.64 writes:
The word "unordered" is there to suggest a "brute-force" algorithm. So, basically you set up a loop that runs for the length of the array (or, optionally, until you've found entries which equal your extreme values - a 1 and a 100). You either initialize your "hi" value to a number lower than any possible value in the list, or to the value of the first entry. That way, even if all 25 of your entries are 1's, your "hi" value will end up being recorded as a one, as well, even though it is the lowest number possible in your specifications. You also initialize the "low" number a number higher than any possible number in the list, or to the first entry in the array. You then loop through and compare the number in the list to the "hi" and "low" values you have so far. You replace the "hi" and "low" values, as needed. Good luck.
MikeD