VB在窗体中显示1000以内的完数
'在窗体中显示1000以内的完数(如果一个整数的所有因子(包括1,但不包括本身)之和与该数相等,则称这个数字为完数。例如6=1+2+3,所以6是一个完数)
Private Function IsWs(ByVal m%, ByRef s$) As Boolean
Dim i%, sum%
s = ""
sum = 0
For i = 1 To m \ 2
If m Mod i = 0 Then
sum = sum + i
s = s & i & "+"
End If
Next i
If sum = m Then
IsWs = True
Else
IsWs = False
End If
End Function
Private Sub Command1_Click()
Dim i%, ss$
For i = 1 To 1000
If IsWs(i, ss) Then
Print i & "=" & Left(ss, Len(ss) - 1)
End If
Next i
End Sub