
Задать массив из 8 элементов целого типа. Заполнить массив случайными значениями из интервала (-10;
10) и вывести массив. Найти сумму и количество четных, а также произведение и количество нечетных значений элементов массива.

Ответы на вопрос

const z = 8;
var
a: array[1..z] of integer;
i, s, s2, n, n2: integer;
begin
s := 0;
s2 := 1;
for i := 1 to z do begin
a[i] := random(21) - 10;
write(a[i], ' ');
if(a[i] mod 2 = 0) then begin {четные}
inc(n);
s := s + a[i];
end else begin
inc(n2);
s2 := s2 * a[i];
end;
end;
writeln;
writeln('Кол-во четных чисел: ', n, ', их сумма: ', s);
writeln('Кол-во нечетных чисел: ', n2, ', их произведение: ', s2);
end.



Sure! Here's an example code in Python that creates an array of 8 integers, fills it with random values from the interval (-10, 10), and then calculates the sum and count of even numbers, as well as the product and count of odd numbers in the array:
pythonimport random
# Create an empty array of size 8
array = [0] * 8
# Fill the array with random values from -10 to 10
for i in range(len(array)):
array[i] = random.randint(-10, 10)
# Print the array
print("Array:", array)
# Calculate the sum and count of even numbers
even_sum = 0
even_count = 0
# Calculate the product and count of odd numbers
odd_product = 1
odd_count = 0
for num in array:
if num % 2 == 0: # Check if the number is even
even_sum += num
even_count += 1
else:
odd_product *= num
odd_count += 1
# Print the results
print("Sum of even numbers:", even_sum)
print("Count of even numbers:", even_count)
print("Product of odd numbers:", odd_product)
print("Count of odd numbers:", odd_count)
Each time you run this code, it will generate a new array with random values, calculate the required statistics, and display the results.


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili