You are given an array A of 20 elements. Replace negative array elements with the arithmetic mean

You are given an array A of 20 elements. Replace negative array elements with the arithmetic mean of array elements. Print the result.

Here is a variant of solving the problem in Pascal. We set the variables of the array A itself, the arithmetic mean s and the counter i. In the first cycle, we immediately organize the input from the keyboard of the array variables and their summation for the subsequent finding of the arithmetic mean. The initial value of the variable s by default is 0. Then we start the loop with a counter again and use the condition operator inside: If the array element is less than zero, then we assign the value s to the element with this number.

var
A: array [1..20] of real;
s: real;
i: integer;
begin
for 1: = 1 to 20 do
begin
writeln (‘Enter’, i, ‘- th element of the array’);
readln (A [i]);
s: = s + A [i];
end;
s: = s / 20;
for 1: = 1 to 20 do
if A [i] <0 then A [i]: = s;
for i: = 1 to 20 write (A [i], ”)
end.



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.