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
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;
for i:=1 to 10 do
a[i]:=random (100);
write(a[i]:3)
for i:=1 to 9 do
for j:=1 to 9 do
if a[j]>a[j+1] then
v:=a[j];
a[j]:=a[j+1];
a[j+1]:=v
for i:=1 to 10 do write(a[i]:3)
3.
var a:array [1..10] of integer;
i,j,m,v:integer;
randomize;
a[i]:=random(100);
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;
1) -165
2) 3
3) -214277011200
4) 0
5) 3 6 9 12 15 18 21 24 27 30
код:
n = []
for i in range(-30, 31, 3):
if i != 0:
n.append(i)
x1, x2, x3, x4, x5 = 0, 0, 1, 0, []
mine = 0
maxe = 0
pos = 0
for i in n:
pos += 1
if i < 0:
x1 += i
if i % 5 == 0 and i < 20:
x2 += 1
if pos % 2 == 0:
x3 *= i
if pos == 1:
mine = i
elif pos == 20:
maxe = i
if i % 3 == 0 and i > 0:
x5.append(str(i))
x4 = mine + maxe
print(' '.join(x5))
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.
1) -165
2) 3
3) -214277011200
4) 0
5) 3 6 9 12 15 18 21 24 27 30
код:
n = []
for i in range(-30, 31, 3):
if i != 0:
n.append(i)
x1, x2, x3, x4, x5 = 0, 0, 1, 0, []
mine = 0
maxe = 0
pos = 0
for i in n:
pos += 1
if i < 0:
x1 += i
if i % 5 == 0 and i < 20:
x2 += 1
if pos % 2 == 0:
x3 *= i
if pos == 1:
mine = i
elif pos == 20:
maxe = i
if i % 3 == 0 and i > 0:
x5.append(str(i))
x4 = mine + maxe
print(' '.join(x5))