
Pascal. Дан массив A[N]. Сформировать массив В из положительных элементов, кратных 3 массива А.


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

begin
var a:=ArrRandom(ReadInteger('n='),-50,50); a.Println;
var b:=a.Where(x->(x>0) and (x mod 3=0)).ToArray.Println
end.
Тестовое решение:
n= 15
15 39 -3 -40 6 -47 -19 -19 17 14 7 31 10 -37 -13
15 39 6



N = 20;
var
a, b: array[1..N] of integer;
i, j: integer;
begin
writeln('Массив A:');
for i := 1 to N do
begin
a[i] := random(199) - 99;
write(a[i] : 4);
if (a[i] > 0) and (a[i] mod 3 = 0) then
begin
j := j + 1;
b[j] := a[i];
end;
end;
writeln;
writeln('Массив B:');
for i := 1 to j do
write(b[i] : 4);
end.
Пример работы программы:
Массив A:
3 73 -1 -35 97 -14 25 34 -79 5 -39 39 45 96 -85 -59 -14 76 -53 -12
Массив B:
3 39 45 96



Pascal: Forming Array B from Array A
To form an array B from array A containing positive elements that are multiples of 3, you can use the following Pascal code:
```pascal program FormArrayB; var A: array[1..N] of Integer; // Assuming N is the size of array A B: array[1..N] of Integer; i, j: Integer; begin j := 1; for i := 1 to N do begin if (A[i] > 0) and (A[i] mod 3 = 0) then begin B[j] := A[i]; j := j + 1; end; end; end. ```
In this code, we iterate through array A, and for each positive element that is a multiple of 3, we add it to array B. The variable j is used to keep track of the current position in array B.
This code assumes that the size of array A is represented by N. You would need to replace N with the actual size of array A in your specific implementation.
This approach ensures that array B only contains positive elements that are multiples of 3 from array A.
Let me know if you need further assistance with Pascal or any other programming-related queries!


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









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