读书人

找出1-1000之间的完全数。如6=1+2+3

发布时间: 2012-05-02 15:36:04 作者: rapoo

找出1--1000之间的完全数。如6=1+2+3,6即为完全数。
求高手写出源代码,急急急急急急!!!!!!!!!!!!

[解决办法]

VB code
Private Sub Command1_Click()    Dim i As Long    Dim j As Long    Dim s As Long    Dim text As String        For i = 1 To 1000        s = 0        text = "="        For j = 1 To i - 1            s = s + j            text = text & CStr(j) & "+"            If (s = i) Then                text = Left(text, Len(text) - 1)                Debug.Print (s & text)                Exit For            End If        Next    NextEnd Sub 

读书人网 >VB

热点推荐