Loops

How would I create a program that would find the largest and the smallest integer in a series?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Returns the minimum value from a range [first, last)
template <class Iter>
typename std::iterator_traits<Iter>::value_type
	MinRange(Iter first, Iter last)
{
	typename std::iterator_traits<Iter>::value_type lowVal = *first++;
	for ( ; first != last; ++first)
		if (*first < lowVal)
			lowVal = *first;
	return lowVal;
}

// Returns the maximum value from a range [first, last)
template <class Iter>
typename std::iterator_traits<Iter>::value_type
	MaxRange(Iter first, Iter last)
{
	typename std::iterator_traits<Iter>::value_type highVal = *first++;
	for ( ; first != last; ++first)
		if (highVal < *first)
			highVal = *first;
	return highVal;
}
or more simply:
1
2
3
4
5
6
7
8
float MaxRange(float arr[], int size)
{
    float highVal = arr[0];
    for (int i = 1; i < size; ++i)
        if (highVal < arr[i];
            highVal = arr[i];
    return highVal;
}
Topic archived. No new replies allowed.