VB编程:利用循环嵌套求1000以内的完数
运行效果:
编写总结
完数:它的因子之和恰好等于它的本身;
亏数:它的因子之和小于本身;
盈数:它的因子之和大于本身;
程序代码:
Private Sub Form_Click()
Dim n, r, j, i As Integer
n = 1000
Me.Cls
For i = 1 To n - 1
r = 0
For j = 1 To i - 1
If i Mod j = 0 Then
r = r + j '累加因子
End If
Next
If r = j Then '判断完数:数字=因子之和
Print Str(r) + "的因子是:";
For j = 1 To i - 1
If i Mod j = 0 Then
Print Str(j) + ";";
End If
Next
Print
End If
Next
End Sub