Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAXELS = 5;
  5. int findMax(int [MAXELS]); // function prototype
  6.  
  7. int main()
  8. {
  9. int nums[MAXELS] = {2, 18, 1, 27, 16};
  10.  
  11. cout << "The maximum value is " << findMax (nums) << endl;
  12.  
  13. return 0;
  14. }
  15.  
  16. // find the maximum value
  17. int findMax(int vals[MAXELS])
  18. {
  19. int i, max = vals[0];
  20.  
  21. for (i = 1; 1 < MAXELS; i++)
  22. if (max < vals[i])
  23. max = vals[i];
  24.  
  25. return max;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement