计算机二级vb上机试题
10.设n是一个正整数,d是它的因子,若d和n/d互质,则称d为n的酉因子。如果n等于它的酉因子和(不包括n自身),则称n为酉完全数,编程找出200以内的酉完全数。这个怎...
10. 设n是一个正整数,d是它的因子,若d和n/d互质,则称d为n的酉因子。如果n等于它的酉因子和(不包括n自身),则称n为酉完全数,编程找出200以内的酉完全数。 这个怎么做
要vb代码 展开
要vb代码 展开
2个回答
展开全部
仅仅在窗体上放一个命令按钮(点按钮后结果在窗体上打印出来,只有3个数,6,60,90)
Private Sub Command1_Click()
Print "200以内的酉完全数"
Print
Dim n As Integer, i As Integer, k As Integer, j As Integer, min As Integer, a As Integer
For n = 1 To 200
a = 0
For i = 1 To n - 1
If n Mod i = 0 Then
If i < n / i Then
min = i
Else
min = n / i
End If
For j = 1 To min
If i Mod j = 0 And n / i Mod j = 0 Then
k = j
End If
Next j
If k = 1 Then
a = a + i
End If
End If
Next i
If a = n Then Print n
Next n
End Sub
Private Sub Command1_Click()
Print "200以内的酉完全数"
Dim n As Integer, i As Integer, k As Integer, j As Integer, min As Integer, a As Integer
For n = 1 To 200
a = 0
For i = 1 To n - 1
If n Mod i = 0 Then
If i < n / i Then
min = i
Else
min = n / i
End If
For j = 1 To min
If i Mod j = 0 And n / i Mod j = 0 Then
k = j
End If
Next j
If k = 1 Then
a = a + i
End If
End If
Next i
If a = n Then Print n
Next n
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询