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.
Var ar:array[1..s] of integer; n,m,i:integer; begin writeln('N'); readln(n); writeln('M'); readln(m); writeln('Array:'); for i:=1 to s do readln(ar[i]); writeln('First array:'); for i:=1 to s do begin write(ar[i]:4); if ar[i] div n<>0 then ar[i]:=ar[i]+m; end; writeln; writeln('Final array:'); for i:=1 to s do write(ar[i]:4); end.
Пример ввода: 3 3 1 2 3 4 5 Пример вывода: First array: 1 2 3 4 5 Final array: 1 2 6 7 8
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.
Const
s=5;
Var
ar:array[1..s] of integer;
n,m,i:integer;
begin
writeln('N');
readln(n);
writeln('M');
readln(m);
writeln('Array:');
for i:=1 to s do
readln(ar[i]);
writeln('First array:');
for i:=1 to s do
begin
write(ar[i]:4);
if ar[i] div n<>0 then ar[i]:=ar[i]+m;
end;
writeln;
writeln('Final array:');
for i:=1 to s do
write(ar[i]:4);
end.
Пример ввода:
3
3
1
2
3
4
5
Пример вывода:
First array:
1 2 3 4 5
Final array:
1 2 6 7 8
//Блок-схема во вложении