C++ Programming

 

Finding Maximum Value


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;
}

 


DISCLAIMER

Paked and the contributors are not responsible for any errors contained and are not liable for any damages resulting from the use of this material.  (Disclaimer)

 

 

Home     Disclaimer     Advertise      Contact us     

Copyright © 2006-08 Paked.com. All rights reserved.

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

 

footer image footer image