Arrays and Vectors

std::vector — an array: reading n elements, traversing and finding the maximum.

An array stores many values of the same type under one name. In modern C++, instead of "raw" arrays you use std::vector — an array that knows its own size and can grow. Elements are numbered from zero: in a vector of n elements the indices run from 0 to n-1. Going out of bounds is one of the most common causes of a Runtime Error verdict.
C++

Enter: 5, then 1 3 5 2 4

The program above reads an array and prints it in reverse order — note the loop that steps backwards. The second basic technique is finding the maximum: take the first element as the "current maximum" and update it in a loop whenever you find a larger element.
C++

Finding the maximum. Enter: 5, then 1 3 5 2 4

Task: using the same idea, find the minimum of the array and print it together with the maximum, separated by a space. Then solve the attached problem "Maximum in an Array" and mark the lesson as completed.

Practice problems

Доска