
求 1000以内的完全数 的VB代码!!
3个回答
推荐于2018-02-27
展开全部
Option Explicit
Option Base 1
Private Sub command1_click()
Dim I As Integer, A() As Integer
Dim K As Integer, sum1 As Integer, sum2 As Integer
For I = 2 To 1000
sum1 = 0: sum2 = 0
Call fctor(I, sum1)
Call fctor(sum1, sum2)
If sum2 = 2 * I Then
K = K + 1
ReDim Preserve A(K)
A(K) = I
End If
Next I
For I = 1 To K
Text1.Text = Text1.Text & Str(A(I)) & " "
Next I
End Sub
Private Sub fctor(N As Integer, S As Integer)
Dim I As Integer, J As Integer
Do While I <= N
I = I + 1
If N Mod I = 0 Then
S = S + I
End If
Loop
End Sub
Option Base 1
Private Sub command1_click()
Dim I As Integer, A() As Integer
Dim K As Integer, sum1 As Integer, sum2 As Integer
For I = 2 To 1000
sum1 = 0: sum2 = 0
Call fctor(I, sum1)
Call fctor(sum1, sum2)
If sum2 = 2 * I Then
K = K + 1
ReDim Preserve A(K)
A(K) = I
End If
Next I
For I = 1 To K
Text1.Text = Text1.Text & Str(A(I)) & " "
Next I
End Sub
Private Sub fctor(N As Integer, S As Integer)
Dim I As Integer, J As Integer
Do While I <= N
I = I + 1
If N Mod I = 0 Then
S = S + I
End If
Loop
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-06-14
展开全部
dim i,j,a as integer
for i=2 to 1000
a=0
for j=1 to i-1
if i mod j=0 then a=a+j'判断j是否能整除i,如果能,则a增加j
next j
if a=i then print i'判断i是否是完全数,如果是,则输出i
next i
运行输出:
6
28
496
for i=2 to 1000
a=0
for j=1 to i-1
if i mod j=0 then a=a+j'判断j是否能整除i,如果能,则a增加j
next j
if a=i then print i'判断i是否是完全数,如果是,则输出i
next i
运行输出:
6
28
496
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-14
展开全部
哈哈
GamesBug.NO2身手好快!我刚刚复制好代码,你已经提交了……
GamesBug.NO2身手好快!我刚刚复制好代码,你已经提交了……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询