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.
uses crt; var i,j,max:byte; a: array [1..100] of integer; buf:integer; BEGIN repeat write(' input number of elements '); readln(max); until max in [1..100]; writeln('input your demention'); for i:=1 to max do begin write('input a[', i, '] = '); readln(a[i]); end; buf:=0; write('the first sort: '); for i:=max downto 1 do for j:=2 to i do if a[j]<a[j-1] then begin buf:=a[j]; a[j]:=a[j-1]; a[j-1]:=buf; end; for i:=1 to max do write(a[i]); writeln; write('the second sort : '); for i:=max downto 1 do write(a[i],' '); 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.
С форума программистов , сортировка повсюду