|
|
|
|
Finding Maximum ValueBinary Search | Bubble Sort | Selection Sort | Finding Maximum Value | Linear Search | Celsius to Fahrenheit | 10 Pseudo-random numbers | Calculating Average | Swapping Values | Lowercase/ Uppercase C++ Source Code #include <iostream.h>
int FindMax(int [], int); // function prototype
int main()
{
const int MAXELS = 5;
int nums[MAXELS] = {2, 18, 1, 27, 16};
cout << "The maximum value is " << FindMax(nums, MAXELS) << endl;
return 0;
}
// find the maximum value
int FindMax(int vals[], int numEls)
{
int i, max = vals[0];
for (i = 1; i < numEls; i++)
if (max < vals[i])
max = vals[i];
return max;
}
Copyrights Gary Bronson. "A First Book of C++: From Here to There " Thomson Learning. |
|
|
|