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.
1.
program test;
var i,k2,k3,k4,k5:integer;
a:array [1..20] of integer;
begin
k2:=0;
k3:=0;
k4:=0;
k5:=0;
for i:=1 to 20 do
begin
a[i]:=random(4)+2;
if a[i]=2 then k2:=k2+1;
if a[i]=3 then k3:=k3+1;
if a[i]=4 then k4:=k4+1;
if a[i]=5 then k5:=k5+1;
write(a[i],' ')
end;
writeln;
writeln(k2);
writeln(k3);
writeln(k4);
write(k5)
end.
2.
var i,j,v:integer;
a:array [1..10] of integer;
begin
for i:=1 to 10 do
begin
a[i]:=random (100);
write(a[i]:3)
end;
for i:=1 to 9 do
for j:=1 to 9 do
if a[j]>a[j+1] then
begin
v:=a[j];
a[j]:=a[j+1];
a[j+1]:=v
end;
writeln;
for i:=1 to 10 do write(a[i]:3)
end.
3.
var a:array [1..10] of integer;
i,j,m,v:integer;
begin
randomize;
for i:=1 to 10 do
begin
a[i]:=random(100);
write(a[i]:3)
end;
writeln;
for i:=1 to 10 do
begin
m:=i;
for j:=i to 10 do
if a[m] mod 10 < a[j] mod 10 then m:=j;
v := a[i];
a[i]:= a[m];
a[m] := v;
write(a[i]:3)
end;
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.