Написать в vba, используя подпрограмму: натуральное число, в записи которого n цифр, называется числом амстронга, если сумма его цифр, возведенных в степень n равна самому числу. найти все эти числа от 1 до k.
Function IsArmstrong(m As Long) As Boolean Dim s As Long, n As Integer, i As Integer, m1 As Long Dim d(1 To 15) As Long m1 = m: n = 0 Do While m1 > 0 n = n + 1 d(n) = m1 Mod 10 m1 = Int(m1 / 10) Loop s = 0 For i = 1 To n s = s + d(i) ^ n Next i IsArmstrong = (s = m) End Function
Sub Test() Dim k As Long, i As Long, j As Integer Cells.Clear k = CLng(InputBox("Введите значение k")) j = 1 For i = 0 To k If IsArmstrong(i) Then Cells(j, 1) = i j = j + 1 End If Next i End Sub
Dim s As Long, n As Integer, i As Integer, m1 As Long
Dim d(1 To 15) As Long
m1 = m: n = 0
Do While m1 > 0
n = n + 1
d(n) = m1 Mod 10
m1 = Int(m1 / 10)
Loop
s = 0
For i = 1 To n
s = s + d(i) ^ n
Next i
IsArmstrong = (s = m)
End Function
Sub Test()
Dim k As Long, i As Long, j As Integer
Cells.Clear
k = CLng(InputBox("Введите значение k"))
j = 1
For i = 0 To k
If IsArmstrong(i) Then
Cells(j, 1) = i
j = j + 1
End If
Next i
End Sub