Datasets contain height values for girls and boys. Determine who (boy or girl) is the tallest and smallest.
Answer 1, authority 100%
Find maximum element:
int m [5] = {1, -1, 0, 4, 2};
int max = m [0];
for (int i = 0; i & lt; 5; ++ i)
{
if (m [i] & gt; max)
{
max = m [i];
}
}
Find the minimum:
int m [5] = {1, -1, 0, 4, 2};
int min = m [0];
for (int i = 0; i & lt; 5; ++ i)
{
if (m [i] & lt; min)
{
min = m [i];
}
}
Here are the algorithms for you, check in a loop each element in the maximum (minimum), and if it is more (less) then we change the maximum (minimum) element. Google is full of examples, a popular starter theme.
Answer 2, authority 50%
The minmax_element
algorithm from the STL will help you.