4、/*一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程 找出1000以内的所
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 11:49:11
4、/*一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程 找出1000以内的所
4、/*一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程 找出1000以内的所
4、/*一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程 找出1000以内的所
Dim i As Integer,j As Integer,num(100) As Integer,num1(30)
Private Sub Form_Load()
Dim k As Integer,p As Integer,p2 As Integer,p3 As Integer,p4 As Integer,h As String
k = 0
p = 0
p2 = 0
p3 = 0
p4 = 0
For i = 1 To 1000
For j = 1 To i - 1
If i Mod j = 0 Then
num(k) = j
k = k + 1
num(k) = i \ j
k = k + 1
End If
Next j
For j = 0 To k - 1
If num(j) i Then
For p2 = 1 To j - 1
If num(j) = num(p2) Then
p3 = 1
End If
Next p2
If p3 = 0 Then
p = num(j) + p
num1(p4) = num(j)
p4 = p4 + 1
End If
p3 = 0
End If
Next j
If p = i Then
Text1.Text = Text1.Text & ";" & i & "的因子是"
For k = 0 To p4 - 1
Text1.Text = Text1.Text & num1(k) & ","
Next k
End If
p = 0
k = 0
p4 = 0
Next i
End Sub
这段代码可以查出1000以内的完数,并显示出其因子,如果不要显示其因子的话可以简单很多