Вопрос задан 11.01.2020 в 16:47. Предмет Информатика. Спрашивает Резниченко Родион.

в паскале Сформировать массив из положительных элементов и найти их произведение

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

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

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

uses crt;
var a:array[1..10] of integer;
i,s:integer;
begin
writeln('Исходный массив:');
for i:=1 to 10 do begin
a[i]:=random(10-1+1)+1;
write(a[i]:4);
end;
s:=1;
for i:=1 to 10 do begin
s:=s*a[i];
end;
writeln;
writeln('Произведение элементов: ',s);
end.

 

В массиве 10 элементов, которые заданы случайно в пределах от 1 до 10. 

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

Pascal Code to Form an Array of Positive Elements and Find their Product

To form an array of positive elements and find their product in Pascal, you can follow these steps:

1. Declare an array to store the elements. 2. Initialize the array with some values. 3. Iterate over the array and check if each element is positive. 4. If an element is positive, add it to a new array. 5. Calculate the product of the positive elements in the new array.

Here's an example code snippet that demonstrates this:

```pascal program PositiveElementsProduct;

const MAX_SIZE = 10;

var originalArray: array[1..MAX_SIZE] of Integer; positiveArray: array[1..MAX_SIZE] of Integer; product: Integer; i, j, count: Integer;

begin // Initialize the original array with some values originalArray[1] := 1; originalArray[2] := -2; originalArray[3] := 3; originalArray[4] := -4; originalArray[5] := 5; originalArray[6] := -6; originalArray[7] := 7; originalArray[8] := -8; originalArray[9] := 9; originalArray[10] := -10;

// Iterate over the original array and add positive elements to the positive array count := 0; for i := 1 to MAX_SIZE do begin if originalArray[i] > 0 then begin count := count + 1; positiveArray[count] := originalArray[i]; end; end;

// Calculate the product of the positive elements product := 1; for j := 1 to count do begin product := product * positiveArray[j]; end;

// Display the product of the positive elements writeln('Product of positive elements:', product);

end. ```

In this example, we have an original array of size 10. We initialize it with some values, including both positive and negative numbers. We then iterate over the original array and add the positive elements to the positive array. Finally, we calculate the product of the positive elements in the positive array and display the result.

Please note that you can modify the size of the array and the initial values according to your requirements.

Let me know if you have any further questions!

0 0

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

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

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