Data arrays contain growth values for girls and boys. Determine who (boy or girl) is the tallest and smallest.
Closed due to the fact that off-topic participants are Vladimir Martyanov , aleksandr barakin , Harry , Nicolas Chabanovsky ♦ 19 Apr '16 at 7:53 .
- Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
- fourI vote for closing this question as irrelevant to the topic, because it’s just a request to complete the training task without doing anything on your own - Harry
|
2 answers
Search for the maximum element:
int m[5] = {1, -1, 0, 4, 2}; int max = m[0]; for(int i = 0; i < 5; ++i) { if(m[i] > max) { max = m[i]; } } Minimum search:
int m[5] = {1, -1, 0, 4, 2}; int min = m[0]; for(int i = 0; i < 5; ++i) { if(m[i] < min) { min = m[i]; } } Here are the algorithms for you to check every element in the cycle at the maximum (minimum), and if it is more (less), then change the maximum (minimum) element. Google is full of examples, a popular starting topic.
|
The minmax_element algorithm from STL will help you.
|