Вопрос задан 02.05.2019 в 22:19. Предмет Информатика. Спрашивает Алексеева Соня.

Задан массив А(1:20). Найти произведение всех его ненулевых элементов. На паскале через массивы!)

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

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Зубко Ира.
Var
  i,p:integer;
  a:array[1..20]of integer;
begin
writeln('Массив: ');
p:=1;
for i:=1 to 20 do
  begin
  a[i]:=random(10);
  write(a[i],' ');
  if a[i]<>0 then p:=p*a[i];
  end;
writeln;
writeln('Произведение ненулевых: ',p);
end.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Finding the Product of Non-Zero Elements in Pascal

To find the product of all non-zero elements in the array A(1:20) in Pascal, you can use a simple loop to iterate through the array and multiply the non-zero elements together. Here's a sample Pascal code to achieve this:

```pascal program ProductOfNonZeroElements; var A: array[1..20] of Integer; i: Integer; product: Integer; begin product := 1; { Initialize the array A with values } { ... }

{ Calculate the product of non-zero elements } for i := 1 to 20 do begin if A[i] <> 0 then product := product * A[i]; end;

{ Display the product } writeln('The product of non-zero elements in the array A is: ', product); end. ```

In this code, we declare an array A of size 20 and initialize it with values. Then, we iterate through the array and multiply the non-zero elements together to calculate the product. Finally, we display the product of the non-zero elements.

I hope this helps! Let me know if you have further questions or need additional assistance.

0 0

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

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

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