Write a program that fills the array b [1 … 8] with random integers in the range from 1 to 10
Write a program that fills the array b [1 … 8] with random integers in the range from 1 to 10 and finds the number of elements with odd values
All numbers in the array will be integers. Let’s create an array of 8 integers from 1 to 10:
var a: array [1..8] of integer;
We will also create a variable into which we will write the number of odd elements. It will also be whole:
col-vo: integer;
for i: integer≔1 to 8 do
a [i] ≔ random (9) + 1;
The maximum number that random can create is 9. By adding 1 to it, we get 10 maximum.
The minimum number that random can create is 0. Add 1 to it and we get the minimum number 1.
for i: integer≔1 to 8 do
if (a [i] mod 2 <> 0) then
begin
col-vo ≔ col-vo + 1;
write (a [i]: 5);
end;
writeln (‘In an array’, col-vo, ‘odd elements’);