C++ Array Initialization, for loop to find the maximum value

Description

C++ Array Initialization, for loop to find the maximum value

#include <iostream>
using namespace std;
int main()/*w  w w  .  jav  a2  s  . c o m*/
{
   const int MAXELS = 5;
   int i, max, nums[MAXELS] = {2, 18, 1, 27, 16};
   max = nums[0];
   for (i = 1; i < MAXELS; i++) {
      if (max < nums[i]) {
         max = nums[i];
      }
   }
   cout << "The maximum value is " << max << endl;
   return 0;
}



PreviousNext

Related