FunctionX - Practical Learning Logo

Minimum Value in a Range

This Min() function is used to find the maximum value in a list

#include <iostream>

using namespace std;



int Min(const int *Numbers, const int Count)

{

	int Minimum = Numbers[0];



	for(int i = 0; i < Count; i++)

		if( Minimum > Numbers[i] )

			Minimum = Numbers[i];



	return Minimum;

}



double Min(const double *Numbers, const int Count)

{

	double Minimum = Numbers[0];



	for(int i = 0; i < Count; i++)

		if( Minimum > Numbers[i] )

			Minimum = Numbers[i];



	return Minimum;

}



int main()

{

	int Nbrs[] = { 12, 483, 748, 35, 478 };

	int Total = sizeof(Nbrs) / sizeof(int);



	int Minimum = Min(Nbrs, Total);

	cout << "Minimum: " << Minimum << endl;



	return 0;

}

Here is an example of running the program:

Minimum: 12

Copyright 2003 FunctionX, Inc.