Π‘ΠΈΠ±ΠΈΡΡΠΊΠ°Ρ Π Π΅Π³ΠΈΠΎΠ½Π°Π»ΡΠ½Π°Ρ ΡΠΊΠΎΠ»Π° Π±ΠΈΠ·Π½Π΅ΡΠ° ΠΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ ΡΠ°Π±ΠΎΡΠ° № 1
ΠΠΈΡΡΠΈΠΏΠ»ΠΈΠ½Π°: Visual Basic for Application (VBA)
Π‘ΠΎΠ΄Π΅ΡΠΆΠ°Π½ΠΈΠ΅ ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² vba
ΠΠ°ΡΡΠΈΠ²Ρ Π 3
ΠΠ°Π΄Π°Π½ ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² Q (N). Π Π΄Π°Π½Π½ΠΎΠΌ ΠΌΠ°ΡΡΠΈΠ²Π΅ Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ
Π£Π²Π΅Π»ΠΈΡΠΈΡΡ Π²ΡΠ΅ ΠΊΡΠ°ΡΠ½ΡΠ΅ ΠΏΡΡΠΈ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° Π² Π΄Π²Π° ΡΠ°Π·Π°, Π° Π½Π΅ΡΡΡΠ½ΡΠ΅ ΡΠΌΠ΅Π½ΡΡΠΈΡΡ Π½Π° Π΅Π΄ΠΈΠ½ΠΈΡΡ. ΠΠΎΠ»ΡΡΠ΅Π½Π½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² ΡΠ°ΡΠΏΠ΅ΡΠ°ΡΠ°ΡΡ Π£Π΄Π°Π»ΠΈΡΡ ΠΈΠ· Π²Π½ΠΎΠ²Ρ ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ. ΠΠ°ΡΡΠΈΠ² ΡΠ°ΡΠΏΠ΅ΡΠ°ΡΠ°ΡΡ ΠΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΏΠΎΠ»ΡΡΠ΅Π½Π½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° ΡΠ°ΡΠΏΠΎΠ»ΠΎΠΆΠΈΡΡ ΠΏΠΎ ΡΠ±ΡΠ²Π°Π½ΠΈΡ. ΠΠ°ΡΡΠΈΠ² ΡΠ°ΡΠΏΠ΅ΡΠ°ΡΠ°ΡΡ ΠΠΎ Π²Π½ΠΎΠ²Ρ ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½Π½ΠΎΠΉ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ Π²ΡΡΠΈΡΠ»ΠΈΡΡ ΡΡΠΌΠΌΡ ΡΡΡΠ½ΡΡ
ΠΏΠΎΠ»ΠΎΠΆΠΈΡΠ΅Π»ΡΠ½ΡΡ
ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΈ Π²ΡΡΠ°Π²ΠΈΡΡ ΡΡΠΎ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΠΏΠ΅ΡΠ΅Π΄ ΠΊΠ°ΠΆΠ΄ΡΠΌ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠΌ, ΠΊΡΠ°ΡΠ½ΡΠΌ ΠΎΠ΄ΠΈΠ½Π½Π°Π΄ΡΠ°ΡΠΈ. ΠΠ½Π°ΡΠ΅Π½ΠΈΡ ΡΡΠΌΠΌΡ ΠΈ Π²Π½ΠΎΠ²Ρ ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° ΡΠ°ΡΠΏΠ΅ΡΠ°ΡΠ°ΡΡ
Π Π΅ΡΠ΅Π½ΠΈΠ΅
Π ΡΡΠ΅ΠΉΠΊΠΈ Excel Π²Π²Π΅Π΄ΠΈΡΠ΅ ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ ΡΠΈΡΠ»Π° (12, 5, 21, 15, 20, 55, -13, 75, 23, 45, 100, 92, 2, -4, 6), ΠΎΡΠΊΡΠΎΠΉΡΠ΅ ΠΎΠΊΠ½ΠΎ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° ΠΈ Π²Π²Π΅Π΄ΠΈΡΠ΅ ΡΠ»Π΅Π΄ΡΡΡΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ. N=15.
ΠΡΠΎΠ³ΡΠ°ΠΌΠΌΠ½ΡΠΉ ΠΊΠΎΠ΄:
Option Explicit
Sub pr21()
Dim a (20) As Integer
Dim n As Integer, i As Integer, i0 As Integer, s As Integer, j As Integer
Dim k As Integer, r As Integer
Dim max As Integer, imax As Integer
n = Val (InputBox («ΠΠ²Π΅Π΄ΠΈΡΠ΅ N»))
For i = 1 To n
a (i) = Cells (1, i)
Next i
For i = 1 To n
If a (i) Mod 5 = 0 Then
a (i) = a (i) * 2
End If
If a (i) Mod 5 <> 0 Then
If a (i) Mod 2 <> 0 Then
a (i) = a (i) — 1
End If
End If
Next i
For i = 1 To n
Cells (3, i) = a (i)
Next i
max = -3200
For i = 1 To n
If a (i) > max Then
max = a (i)
imax = (i)
End If
Next i
Cells (5, 1) = «Max=»: Cells (5, 2) = max
For i = imax To n — 1
a (i) = a (i + 1)
Next i
n = n — 1
Cells (7, 1) = «ΠΠΎΠ»ΡΡΠ΅Π½Π½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²»
For i = 1 To 14
Cells (8, i) = a (i)
Next i
For k = 1 To n — 1
For i = 1 To n — k
If a (i) < a (i + 1) Then
r = a (i)
a (i) = a (i + 1)
a (i + 1) = r
End If
Next i
Next k
Cells (10, 1) = «Π£ΠΏΠΎΡΡΠ΄ΠΎΡΠ΅Π½Π½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²»
For i = 1 To 14
Cells (11, i) = a (i)
Next i
s = 0
For i = 1 To n
If a (i) >= 0 Then
If a (i) Mod 2 = 0 Then
s = s + a (i)
End If
End If
Next i
Cells (13, 1) = «Π‘ΡΠΌΠΌΠ° ΡΠ΅ΡΠ½ΡΡ
ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² =»: Cells (13, 4) = s
i = 1
While i <= n
If a (i) = a (i) Then
If a (i) Mod 11 = 0 Then
For j = n + 1 To i + 1 Step -1
a (j) = a (j — 1)
Next j
a (i) = s
n = n + 1
i = i + 2
Else
i = i + 1
End If
End If
Wend
n = n + 1
Cells (15, 1) = «ΠΠΎΠ²ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²»
If i <= n Then
For i = 1 To n
Cells (16, i) = a (i)
Next i
i = i + 1
n = n + 1
End If
End Sub