C++ examples for Data Type:Array
Initialization of array elements in the array declaration statement, uses for loop to find the maximum value in the array.
#include <iostream> using namespace std; int main()//from ww w.ja va 2s. 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; }