Function IsPrime(n As Integer) As Boolean Dim found As Integer found = n Mod 2 = 0 Dim p As Integer p = 3 Do While Not found And p * p <= n found = n Mod p = 0 p = p + 2 Loop IsPrime = Not found End Function
Sub main() Randomize Timer Dim n As Integer, i As Integer, k As Integer n = 100 + Int(Round(899 * Rnd)) ReDim a(1 To n) As Integer ReDim b(1 To n) As Integer i = 0: k = 0 MsgBox n Do While i < n i = i + 1 a(i) = 1000 + Int(Round(8999 * Rnd)) If IsPrime(a(i)) Then k = k + 1 b(k) = a(i) End If Loop Rows("1:1000").Clear Range(Cells(1, 1), Cells(n, 1)) = a For i = 1 To k Cells(i, 1) = a(i) Cells(i, 2) = b(i) Next i If k > 1 Then 'Сортировка второй колонки, так красивее Dim r As Range Set r = Range(Cells(1, 2), Cells(k, 2)) r.Sort Range("B1") End If For i = k + 1 To n Cells(i, 1) = a(i) Next i End Sub
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
Dim found As Integer
found = n Mod 2 = 0
Dim p As Integer
p = 3
Do While Not found And p * p <= n
found = n Mod p = 0
p = p + 2
Loop
IsPrime = Not found
End Function
Sub main()
Randomize Timer
Dim n As Integer, i As Integer, k As Integer
n = 100 + Int(Round(899 * Rnd))
ReDim a(1 To n) As Integer
ReDim b(1 To n) As Integer
i = 0: k = 0
MsgBox n
Do While i < n
i = i + 1
a(i) = 1000 + Int(Round(8999 * Rnd))
If IsPrime(a(i)) Then
k = k + 1
b(k) = a(i)
End If
Loop
Rows("1:1000").Clear
Range(Cells(1, 1), Cells(n, 1)) = a
For i = 1 To k
Cells(i, 1) = a(i)
Cells(i, 2) = b(i)
Next i
If k > 1 Then 'Сортировка второй колонки, так красивее
Dim r As Range
Set r = Range(Cells(1, 2), Cells(k, 2))
r.Sort Range("B1")
End If
For i = k + 1 To n
Cells(i, 1) = a(i)
Next i
End Sub
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
//Блок-схема во вложении