Вопрос задан 31.07.2018 в 23:42. Предмет Информатика. Спрашивает Рахматуллина Алсина.

Набрать программу нахождения суммы всех элементов массива и подсчитать количество элементов массива

0 0
Перейти к ответам

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

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

CONST max=12;
VAR
i:byte;
sum:integer;
vt:array [1..max] of shortint;

BEGIN
randomize;
writeln('Начальный массив');
for i:=1 to max do begin
vt[i]:=random(-32,127);
write(vt[i]:6);
end;
writeln();

for i:=1 to max do
sum:=sum+vt[i];
writeln('Сумма элементов: ', sum);
END.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program to Find the Sum and Count of Array Elements

Here is a program in Python to find the sum of all elements in an array and count the number of elements in the array:

```python def sum_and_count(array): sum_of_elements = sum(array) count_of_elements = len(array) return sum_of_elements, count_of_elements

# Example usage my_array = [2, 4, 6, 8, 10] sum_result, count_result = sum_and_count(my_array) print("Sum of elements:", sum_result) print("Count of elements:", count_result) ```

This program defines a function called `sum_and_count` that takes an array as input. It uses the `sum` function to calculate the sum of all elements in the array and the `len` function to count the number of elements in the array. The function then returns the sum and count as a tuple.

In the example usage, we create an array called `my_array` with some values. We pass this array to the `sum_and_count` function and store the returned sum and count in variables `sum_result` and `count_result`, respectively. Finally, we print the sum and count of the elements in the array.

Note: This program assumes that the array contains numeric values. If the array contains non-numeric values, it may result in an error.

0 0

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

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

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