VB 试编写程序,求3到1000间的所有完全数

2024-11-15 06:14:22
推荐回答(2个)
回答(1):

完全数的概念不太清楚,1是完全数么?
Public Function IsEntirety(ByVal N As Integer) As Boolean
'判断N是否为完全数
Dim sum As Integer, i As Integer
Do
i = i + 1
If N Mod i = 0 Then sum = sum + i
Loop Until i > N \ 2
IsEntirety = sum = N
End Function

回答(2):

Private Sub Form_Click()
Dim i As Integer, n As Integer
For i = 3 To 1000
If WQS(i) = True Then
Print i;
n = n + 1
If n Mod 5 = 0 Then Print
End If
Next i
End Sub

Private Function WQS(x As Integer)
Dim sum As Integer, i As Integer
For i = 1 To x / 2
If x Mod i = 0 Then sum = sum + i
Next
If sum = x Then WQS = True
End Function