// sequential search for a maximum number #include #include // rand & srand #include // time using namespace std; const int LENGTH = 5; // number of random integers int main() { int numbers[LENGTH]; // random integers int i = 0; // loop variable int maxValue = 0; // maximum random integer srand(1); // or srand(time(NULL)); for (i = 0; i < LENGTH; i++) { numbers[i] = rand() % 50 + 1; // random integers between 1 and 50 cout << numbers[i] << " "; } for (i = 0; i < LENGTH; i++) // linear search for max value { if (numbers[i] > maxValue) // if next number is greater than the max found so far... { maxValue = numbers[i]; // ...replace the max found so far with this new value } } cout << "\n\nThe max value in the array is " << maxValue << endl; system("pause"); return 0; }// end of main