Друзья, нужна помощь. Никак не могу справится, особенно с синеньким, ее заставили решать с помощью массива, а я тютю(((
Answers & Comments
mesteron98
Синяя карточка program qq; const n =10; var i :integer; var a: array[1..n] of integer; var b:boolean; begin b:=false; for i:= 1 to n do begin readln (a[i]); end; for i:= 1 to n-1 do begin if a[i] = a[i+1] then b:= true; end; writeln (b); end. вторая задача const nmax=50; var a:array [1..nmax] of integer; b:array [1..nmax] of integer; i,k,n:integer; function pr_num(x:integer):boolean; var j: integer; b: boolean; begin j:=2; b:=true; while ((j<=x/2)and(b)) do begin if (x mod j = 0) then b:=false; j:=j+1; end; pr_num:=b; end; begin write('Vvedite kol-vo elementov: '); readln(n); k:=1; randomize; for i:=1 to n do a[i]:=random(101); writeln('Ishodnyi massiv: '); for i:=1 to n do write(a[i],' '); for i:=1 to n do if (pr_num(a[i])) then begin b[k]:=a[i]; k:=k+1; end; writeln(); writeln('Poluchennyi massiv: '); for i:=1 to k-1 do write(b[i],' '); writeln(); end.
Answers & Comments
program qq;
const n =10;
var i :integer;
var a: array[1..n] of integer;
var b:boolean;
begin
b:=false;
for i:= 1 to n do
begin
readln (a[i]);
end;
for i:= 1 to n-1 do
begin
if a[i] = a[i+1] then
b:= true;
end;
writeln (b);
end.
вторая задача
const nmax=50;
var a:array [1..nmax] of integer;
b:array [1..nmax] of integer;
i,k,n:integer;
function pr_num(x:integer):boolean;
var j: integer;
b: boolean;
begin j:=2;
b:=true;
while ((j<=x/2)and(b)) do
begin
if (x mod j = 0) then
b:=false;
j:=j+1;
end;
pr_num:=b;
end;
begin
write('Vvedite kol-vo elementov: ');
readln(n);
k:=1;
randomize;
for i:=1 to n do
a[i]:=random(101);
writeln('Ishodnyi massiv: ');
for i:=1 to n do
write(a[i],' ');
for i:=1 to n do
if (pr_num(a[i])) then
begin
b[k]:=a[i];
k:=k+1;
end;
writeln();
writeln('Poluchennyi massiv: ');
for i:=1 to k-1 do
write(b[i],' ');
writeln();
end.