1. program pr1; uses crt; var n,k,i,t:integer; begin clrscr; write('Введите целое число n='); readln (n); for i:=2 to n do begin t:=0; for k:=2 to n do if i mod k=0 then t:=t+1; if t=1 then write(i:3); end; readln; end.
2.
Program pr2; Var a, b: Integer;
Function NOD(a, b: Integer): Integer; Var tmp, r: Integer; Begin If b > a Then Begin tmp := a; a := b; b := tmp; End; tmp := a; While tmp > 0 Do Begin Result := tmp; tmp := tmp - b; End; End;
Var a: array[1..100] of integer; i,n,bg,nd,s: integer; begin write('n = '); readln(n); randomize; bg:=0; nd:=0; for i:=1 to n do begin a[i]:=random(10); write(a[i],' '); if a[i]=0 then if (bg>0) and (nd=0) then nd:=i else if bg=0 then bg:=i; end; writeln; if bg+nd>1 then begin if (bg mod 2=0) then inc(bg) else bg:=bg+2; if (nd mod 2=0) then dec(nd) else nd:=nd-2; writeln('начало: ',bg,' конец: ',nd); s:=1; repeat s:=s*a[bg]; bg:=bg+2; until bg>nd; writeln('произведение: ',s); end else writeln(0); end.
program pr1;
uses crt;
var n,k,i,t:integer;
begin
clrscr;
write('Введите целое число n=');
readln (n);
for i:=2 to n do begin
t:=0;
for k:=2 to n do
if i mod k=0 then t:=t+1;
if t=1 then write(i:3);
end;
readln;
end.
2.
Program pr2;
Var a, b: Integer;
Function NOD(a, b: Integer): Integer;
Var tmp, r: Integer;
Begin
If b > a Then
Begin
tmp := a;
a := b;
b := tmp;
End;
tmp := a;
While tmp > 0 Do
Begin
Result := tmp;
tmp := tmp - b;
End;
End;
Begin
Write('a = ');
ReadLn(a);
Write('b = ');
ReadLn(b);
Write('НОД: ', NOD(a, b));
ReadLn;
End.
i,n,bg,nd,s: integer;
begin
write('n = '); readln(n);
randomize;
bg:=0; nd:=0;
for i:=1 to n do
begin
a[i]:=random(10);
write(a[i],' ');
if a[i]=0 then
if (bg>0) and (nd=0) then nd:=i
else if bg=0 then bg:=i;
end;
writeln;
if bg+nd>1 then
begin
if (bg mod 2=0) then inc(bg)
else bg:=bg+2;
if (nd mod 2=0) then dec(nd)
else nd:=nd-2;
writeln('начало: ',bg,' конец: ',nd);
s:=1;
repeat
s:=s*a[bg];
bg:=bg+2;
until bg>nd;
writeln('произведение: ',s);
end
else writeln(0);
end.
n = 15
4 4 7 0 3 5 6 1 1 8 8 4 0 1 9
начало: 5 конец: 11
произведение: 144