用动态数组写了一道vb,关于 求1000以内所有完数输出时以n=因子和形式,求大神看哪里错了(不胜感激!)
OptionBase1PrivateSubCommand1_Click()DimiAsInteger,jAsIntegerDimsumAsIntegerDima()AsI...
Option Base 1Private Sub Command1_Click() Dim i As Integer, j As Integer Dim sum As Integer Dim a() As Integer Picture1.Print "1000以内的完数:" For i = 2 To 1000 ReDim a(1) a(1) = 1 k = 1: sum = 1 For j = 2 To i - 1 If i Mod j = 0 Then k = k + 1 ReDim Preserve a(k) a(k) = j sum = sum + a(k) End If Next j If i = sum Then Picture1.Print i; "="; For j = 1 To k - 1 Picture1.Print a(j); "+"; Next j Picture1.Print a(j); "+"; a(k) & vbCrLf End If Next i End Sub两个问题1.为什么每一个完数的拆分因子最后都会多出一个?(如图红线划出部分)2. 为什么我打出来的三行都是每行之间隔了一行?怎么打成每行之间无间隔希望可以给我个正确代码 T-T
展开
展开全部
Option Base 1
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim sum As Integer
Dim a() As Integer
Picture1.Print "1000以内的完数:"
For i = 2 To 1000
ReDim a(1)
a(1) = 1
k = 1: sum = 1
For j = 2 To i - 1
If i Mod j = 0 Then
k = k + 1
ReDim Preserve a(k)
a(k) = j
sum = sum + a(k)
End If
Next j
If i = sum Then
Picture1.Print i; "=";
For j = 1 To k - 1
Picture1.Print a(j); "+";
Next j
Picture1.Print a(j)
End If
Next i
End Sub
2016-12-14
展开全部
把 Picture1.Print a(j); "+"; a(k) & vbCrLf 注释掉,试试。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询