Дана программа:
var i : byte;
a : array[1..10] of integer;
BEGIN
randomize;
for i:=1 to 10 do
begin
a[i]:=random(899)+100;
write(a[i]:4);
end;
writeln;
// Программа должна дописать в строку
// четные элементы массива,
// делящиеся на 3.
END.
Задание:
Доработайте программу таким образом, чтобы из исходного массива случайных целых чисел были отобраны четные делящиеся на 3.
1. program Hello;
var i,j:integer; A:array [1..10, 1..10] of integer;
begin
for i:=1 to 10 do for j:=1 to 10 do readln(A[i,j]);
for i:=1 to 10 do for j:=1 to 10 do if A[i,j] mod 2 = 0 then writeln(A[i,j]);
end.
2. program Hello2;
var i,j,c:integer; A:array [1..3,1..3] of integer;
begin
c:=0;
for i:=1 to 3 do for j:=1 to 10 do readln(A[i,j]);
for i:=1 to 3 do for j:=1 to 10 do if A[i,j] mod 3 = 2 then c:=c+1;
writeln(c);
end.
3. program Hello3;
var i,j,c:integer; A:array [1..3,1..3] of integer;
begin
c:=0;
for i:=2 to 3 do for j:=1 to 10 do readln(A[i,j]);
for i:=2 to 3 do for j:=1 to 10 do if A[i,j-1] + A[i,j] > 30 then c:=c+1;
for i:=2 to 3 do for j:=1 to 10 do if A[i-1,j] + A[i,j] > 30 then c:=c+1;
end.
1. program Hello;
var i,j:integer; A:array [1..10, 1..10] of integer;
begin
for i:=1 to 10 do for j:=1 to 10 do readln(A[i,j]);
for i:=1 to 10 do for j:=1 to 10 do if A[i,j] mod 2 = 0 then writeln(A[i,j]);
end.
2. program Hello2;
var i,j,c:integer; A:array [1..3,1..3] of integer;
begin
c:=0;
for i:=1 to 3 do for j:=1 to 10 do readln(A[i,j]);
for i:=1 to 3 do for j:=1 to 10 do if A[i,j] mod 3 = 2 then c:=c+1;
writeln(c);
end.
3. program Hello3;
var i,j,c:integer; A:array [1..3,1..3] of integer;
begin
c:=0;
for i:=2 to 3 do for j:=1 to 10 do readln(A[i,j]);
for i:=2 to 3 do for j:=1 to 10 do if A[i,j-1] + A[i,j] > 30 then c:=c+1;
for i:=2 to 3 do for j:=1 to 10 do if A[i-1,j] + A[i,j] > 30 then c:=c+1;
end.
Подробнее - на - program Hello;
var i,j:integer; A:array [1..10, 1..10] of integer;
begin
for i:=1 to 10 do for j:=1 to 10 do readln(A[i,j]);
for i:=1 to 10 do for j:=1 to 10 do if A[i,j] mod 2 = 0 then writeln(A[i,j]);
end.
2. program Hello2;
var i,j,c:integer; A:array [1..3,1..3] of integer;
begin
c:=0;
for i:=1 to 3 do for j:=1 to 10 do readln(A[i,j]);
for i:=1 to 3 do for j:=1 to 10 do if A[i,j] mod 3 = 2 then c:=c+1;
writeln(c);
end.
3. program Hello3;
var i,j,c:integer; A:array [1..3,1..3] of integer;
begin
c:=0;
for i:=2 to 3 do for j:=1 to 10 do readln(A[i,j]);
for i:=2 to 3 do for j:=1 to 10 do if A[i,j-1] + A[i,j] > 30 then c:=c+1;
for i:=2 to 3 do for j:=1 to 10 do if A[i-1,j] + A[i,j] > 30 then c:=c+1;
end.
Подробнее - на -
Объяснение: