Var ar:array[1..n] of integer; ar2:array[1..n] of integer; i,k:integer;
function prost(a:integer):boolean; var i:integer; b:boolean; begin b:=true; for i:=2 to a div 2 do if a mod i=0 then begin; b:=false; break; end; if a=1 then b:=false; prost:=b; end;
begin; randomize; k:=0; for i:=1 to n do begin; ar[i]:=random(101); write(ar[i]:4); end; writeln; for i:=1 to n do if prost(ar[i]) then begin; inc(k); ar2[k]:=ar[i]; write(ar2[k]:4); end; end.
// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 begin var a:=MatrixRandom(7,7,0,9); var k:=0; for var i:=0 to 6 do begin for var j:=0 to 6 do begin Write(a[i,j]:3); if a[i,j] in [1..5] then Inc(k) end; Writeln end; Writeln('Кол-во элементов на [1,5]: ',k) end.
const n=7; var a:array[1..n,1..n] of integer; i,j,k:integer; begin Randomize; k:=0; for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(10); Write(a[i,j]:3); if a[i,j] in [1..5] then Inc(k) end; Writeln end; Writeln('Кол-во элементов на [1,5]: ',k) end.
n=5;
Var
ar:array[1..n] of integer;
ar2:array[1..n] of integer;
i,k:integer;
function prost(a:integer):boolean;
var i:integer;
b:boolean;
begin
b:=true;
for i:=2 to a div 2 do
if a mod i=0 then
begin;
b:=false;
break;
end;
if a=1 then b:=false;
prost:=b;
end;
begin;
randomize;
k:=0;
for i:=1 to n do
begin;
ar[i]:=random(101);
write(ar[i]:4);
end;
writeln;
for i:=1 to n do
if prost(ar[i]) then
begin;
inc(k);
ar2[k]:=ar[i];
write(ar2[k]:4);
end;
end.
begin
var a:=MatrixRandom(7,7,0,9);
var k:=0;
for var i:=0 to 6 do begin
for var j:=0 to 6 do begin
Write(a[i,j]:3);
if a[i,j] in [1..5] then Inc(k)
end;
Writeln
end;
Writeln('Кол-во элементов на [1,5]: ',k)
end.
Тестовое решение:
2 1 7 3 3 2 7
9 2 9 2 0 5 5
4 2 6 9 4 6 0
1 0 3 5 4 5 9
6 3 6 0 2 0 8
0 8 4 3 2 1 8
6 0 4 4 5 4 0
Кол-во элементов на [1,5]: 27
Вариант "совсем для школы"
const
n=7;
var
a:array[1..n,1..n] of integer;
i,j,k:integer;
begin
Randomize;
k:=0;
for i:=1 to n do begin
for j:=1 to n do begin
a[i,j]:=Random(10);
Write(a[i,j]:3);
if a[i,j] in [1..5] then Inc(k)
end;
Writeln
end;
Writeln('Кол-во элементов на [1,5]: ',k)
end.