You are given an array C with n elements. Increase all positive elements of array C by 0.4, replace zero elements
You are given an array C with n elements. Increase all positive elements of array C by 0.4, replace zero elements by 0.5, determine the sum of negative elements, the product of positive elements.
program zz1;
const n = 10; // set the number of numbers in the array
var i: integer; // set variables of integer type
c: array [1..n] of real; s, k: real;
begin
for i: = 1 to n do // get n random numbers and write them into an array
c [i]: = random (51) -25;
for i: = 1 to n do // display the array on the screen
write (c [i], ”);
writeln; // go to a new line to display the response
k: = 1;
for i: = 1 to n do // organize a loop in which we iterate over all the numbers in the array
begin
if c [i] <0 then s: = s + c [i]; // check if the next element of the array is negative, then its sum
if c [i]> 0 then begin c [i]: = c [i] + 0.4; k: = k * c [i]; end; // check if the next element of the array is positive, then count it
if c [i] = 0 then c [i]: = c [i] + 0.5;
end;
writeln (‘sum of negative array elements =’, s); // display the answer
writeln (‘product of positive array elements =’, k);
end.