求解一道VB题,希望大家帮帮忙
求解一道VB题:如果一个整数的所有因子(包括1,但不包括本身)之和与该数相等,则称这个数为完数。例如6=1+2+3,所以6是一个完数。编写一个函数IsWs(m)判断m是否...
求解一道VB题:如果一个整数的所有因子(包括1,但不包括本身)之和与该数相等,则称这个数为完数。例如6=1+2+3,所以6是一个完数。编写一个函数IsWs(m)判断m是否为完数,函数的返回值使逻辑行。主调程序在列表框显示1000以内的完数
展开
1个回答
展开全部
这个是显示1000以内的完数
Private Sub Form_Click()
Dim i As Integer, s As Long
Dim x As Integer
For x = 1 To 1000
s = 0
For i = 1 To x - 1
If x Mod i = 0 Then s = s + i
Next i
If x = s Then List1.AddItem x
Next x
End Sub
这个是函数IsWs(m)
Private Function isws(ByVal m As Integer) As Boolean
Dim i As Integer, s As Long
For i = 1 To m - 1
If m Mod i = 0 Then s = s + i
Next i
If m = s Then isws = True
End Function
Private Sub Command1_Click()
Dim x As Integer
x = Val(InputBox("请输入要判断的数"))
Print isws(x)
End Sub
Private Sub Form_Click()
Dim i As Integer, s As Long
Dim x As Integer
For x = 1 To 1000
s = 0
For i = 1 To x - 1
If x Mod i = 0 Then s = s + i
Next i
If x = s Then List1.AddItem x
Next x
End Sub
这个是函数IsWs(m)
Private Function isws(ByVal m As Integer) As Boolean
Dim i As Integer, s As Long
For i = 1 To m - 1
If m Mod i = 0 Then s = s + i
Next i
If m = s Then isws = True
End Function
Private Sub Command1_Click()
Dim x As Integer
x = Val(InputBox("请输入要判断的数"))
Print isws(x)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询