Maximum Value in a Range |
|
This Max() function is used to find the maximum value in a list |
#include <iostream> using namespace std; int Max(const int *Numbers, const int Count) { int Maximum = Numbers[0]; for(int i = 0; i < Count; i++) if( Maximum < Numbers[i] ) Maximum = Numbers[i]; return Maximum; } double Max(const double *Numbers, const int Count) { double Maximum = Numbers[0]; for(int i = 0; i < Count; i++) if( Maximum < Numbers[i] ) Maximum = Numbers[i]; return Maximum; } int main() { int Nbrs[] = { 12, 483, 748, 35, 478 }; int Total = sizeof(Nbrs) / sizeof(int); int Maximum = Max(Nbrs, Total); cout << "Maximum: " << Maximum << endl; return 0; }
Here is an example of running the program:
Maximum: 748
|
Copyright © 2003 FunctionX, Inc. |
|