VB找出1000以内的所有完数,输出其因子和
1个回答
展开全部
Private Sub Command1_Click()
'完数定义:一个数如果正好等于它的因子之和,这个数就称为完数。例如,6的因子为1、2、3,而6=1+2+3,因此6是"完数"。
OutputWanNumber 1000
End Sub
Sub OutputWanNumber(ByVal n As Integer)
Dim i As Integer
Dim j As Integer
Dim s As Integer
For i = 1 To n
s = 0
For j = 1 To i\ 2
If i Mod j = 0 Then s = s + j
Next j
If s = i Then Print i & "是完数"
Next i
End Sub
'完数定义:一个数如果正好等于它的因子之和,这个数就称为完数。例如,6的因子为1、2、3,而6=1+2+3,因此6是"完数"。
OutputWanNumber 1000
End Sub
Sub OutputWanNumber(ByVal n As Integer)
Dim i As Integer
Dim j As Integer
Dim s As Integer
For i = 1 To n
s = 0
For j = 1 To i\ 2
If i Mod j = 0 Then s = s + j
Next j
If s = i Then Print i & "是完数"
Next i
End Sub
追问
怎么输出例如6=1+2+3这种形式
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询