Enter the array from the keyboard and find (in one pass) the number of elements that have the maximum value.
June 9, 2021 | education
| Let’s create an array that will contain seven elements and be of type integer, and call it A:
A: array [1..7] of integer;
Let’s fill it in with some arbitrary numbers manually, as stated in the problem:
A [1]: = 5;
A [2]: = 7;
A [3]: = 3;
A [4]: = 7;
A [5]: = 4;
A [6]: = 5;
A [7]: = 7;
Let’s go through it once and add several conditions:
for i: integer: = 1 to 7 do
(if A [1]> max_a) then
begin
max_a: = A [i];
(if kol> 0) then
kol: = 1;
end;
else if (A [i] = max_A)
kol: = kol + 1;
The idea is that when the loop finds a new larger number, it should reset the counter to 1.
And when the element is equal to the maximum, increase the counter.
One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.