题目
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以内的完数,并显示出其因子,如果不要显示其因子的话可以简单很多
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的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点
- 1描写细节的成语,句子和文章
- 2急求一篇800字的议论文,成功来自勤奋.记住一定要是议论文,要有论证方法例如比喻论证,举例论证
- 3有一元、五元、十元的人民币共14张,总计66元,其中一元的比十元的多2张,问三种人民币各有多少张?
- 4椭圆:25分之x的平方加9分之y的平方等于1上的点m到焦点f1的距离为2,n是mf1的中点,则on的绝对值为多少
- 5That is a ruler.改为一般疑问句
- 6《盲孩子和他的影子》问题 盲孩子得到了()、()、()、()、()等的关爱
- 7ax-by=13,cx-y=4,甲同学看错b的符号,得解x=3,y=2.乙同学看错c,得解x=5,y=1,求a,b,c的值
- 8解方程组:0.3x−y=10.2x−0.5y=19
- 9简算,(3/1-0.25)/2/1+6/5
- 10将直线2x-y+λ=0沿x轴向左平移1个单位,所得直线与圆x2+y2+2x-4y=0相切,则实数λ的值为_.