Dim A As Integer, B As Integer, S As Integer, Y As Integer
S = 0
For A = 10 To 1000
B = 0
For Y = 1 To A - 1
If A Mod Y = 0 Then B = B + Y
Next Y
If B = A Then S = S + A
Next A
MsgBox "10到1000的所有完数之和为:" & S
Private Sub Command1_Click()
s = 0
For i = 10 To 1000
If yinzihe(i) = i Then
If k > 0 Then Print "+";
Print i;
s = s + i
k = k + 1
End If
Next i
Print "="; s
End Sub
Function yinzihe(n)
s = 1
For i = 2 To n \ 2
If n Mod i = 0 Then s = s + i
Next i
yinzihe = s
End Function