Вопрос задан 23.02.2021 в 15:40. Предмет Информатика. Спрашивает Романова Оля.

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

10) и вывести массив. Найти сумму и количество четных, а также произведение и количество нечетных значений элементов массива.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Абрамова Даша.

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.

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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:

python
import 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.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос