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


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

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.



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.


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









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