VB编程。找出2到10000的完全数。结果要显示成6=1+2+3的形式

2024-12-20 15:03:26
推荐回答(1个)
回答1:

程序没大问题,有一个小错误,还有由于你的循环次数太多,所以比较慢
Dim i, j, sum As Integer //这里原来把b设置为整形,会出错
dim b as string

For i = 2 To 10000
sum = 0
b = ""
For j = 1 To i / 2
If (i Mod j) = 0 Then
sum = sum + j
If j = 1 Then
b = b & j
Else
b = b & "+" & j
End If
End If
Next
If sum = i Then
TextBox1.Text = TextBox1.Text & i & "=" & b //主要你窗体一定用有textbox1这个对象
End If
Next