当前位置: > 4、/*一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程    找出1000以内的所...
题目
4、/*一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程    找出1000以内的所

提问时间:2021-04-11

答案
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以内的完数,并显示出其因子,如果不要显示其因子的话可以简单很多
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.