Custom Search

 

 

 

 
 

 

Finding Maximum Value


Binary 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.

                        

 

 

 

Custom Search
 

Home      Disclaimer      Advertise      Contact      Privacy Policy     

Copyright 2004-15 Paked.com. All rights reserved.

Note: Site best viewed at 1024 x 768 or higher screen resolution