编程:一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如,6的因数为1,2,3,而6=1+2+3,因此6是完数。编程序找出1000以内的所有完数,并按下面格式输出其因子:
6: its factors are 1,2,3
Private Sub Command1_Click()
For i = 1 To 1000
If is_ws(i) Then
Print Trim(Str(i)); ": its factors are 1";
For j = 2 To i \ 2
If i Mod j = 0 Then Print ","; Trim(Str(j));
Next j
End If
Next i
End Sub
Function is_ws(n) As Boolean
s = 0
For i = 1 To n \ 2
If n Mod i = 0 Then s = s + i
Next i
is_ws = (s = n)
End Function
本回答被提问者和网友采纳