编写一个函数过程,判断已知数m是否为完数。完数

vb程序
2025-01-01 00:53:57
推荐回答(1个)
回答1:

'判断一个数m是否是完数,是则返回True,否则返回False
Function TestWanShu(ByVal m as Long) As Boolean
Dim Sum As Long
Dim i As Long
If m <2 Then
TestWanShu=False
Exit Function
End If
Sum=1
For i=2 To m-1
If m Mod i =0 then Sum=Sum+i
Next
If Sum=m Then
TestWanShu=True
Else
TestWanShu=False
End If
End Function