任意输入一个整数,判断其是否是完全数 VB编程
展开全部
******************************************************************
判断完全数
Private Sub Command1_Click()
Dim X, I, Sum As Long
X = CLng(InputBox("输入一个整数"))
For I = 1 To X - 1
If X Mod I = 0 Then Sum = Sum + I
Next
MsgBox IIf((Sum = X), "是完全数", "不是完全数")
End Sub
判断完全数
Private Sub Command1_Click()
Dim X, I, Sum As Long
X = CLng(InputBox("输入一个整数"))
For I = 1 To X - 1
If X Mod I = 0 Then Sum = Sum + I
Next
MsgBox IIf((Sum = X), "是完全数", "不是完全数")
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Sub form_Click()
Dim a&(), i&, j&, k&, m&, s&, t&
For i = 2 To 10000
Erase a
ReDim a(0)
a(0) = 1
s = 1
For j = 2 To Int(Sqr(i))
m = i Mod j
If m = 0 Then
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = j
s = s + j
t = i \ j
If t > j Then
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = t
s = s + t
End If
End If
Next
If s = i Then Print i
Next
End Sub
Private Sub form_Click()
Dim a&(), i&, j&, k&, m&, s&, t&
For i = 2 To 10000
Erase a
ReDim a(0)
a(0) = 1
s = 1
For j = 2 To Int(Sqr(i))
m = i Mod j
If m = 0 Then
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = j
s = s + j
t = i \ j
If t > j Then
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = t
s = s + t
End If
End If
Next
If s = i Then Print i
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
完全数是啥?网上先看看定义,应该有他自己的规则吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询