I am trying to find the "largest" element in a user array using the max function from the library / header of the algorithm, I did some research on the cplusplus reference site, but there I only saw how to compare two elements using the max function. Instead, I try to display the maximum number using the max function without creating a "for" loop to find it. For example, we have an array [] = {0,1,2,3,5000,5,6,7,8,9}, so the largest number will be 5000. I made this code, but it gives me a bunch of errors, which might be a problem?
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int array[11];
int n = 10;
for (int i = 0; i < n; i++) {
array[i] = i;
}
array[5] = 5000;
max(array , array + n);
for (int i = 0; i < n; i++)
cout << array[i] << " ";
return 0;
}
source
share