VB的一個小問題

2014-01-04 10:52 pm
Dim x As Integer
Dim t As String = ""

For i = 1 To 1000
For j = 1 To i - 1
If i Mod j = 0 Then
x = x + j
t = t & j & "+"
End If
Next

If i = x Then
Debug.Print(i & "=" & t)
End If
x = 0
t = ""
Next

印出來會變成
6=1+2+3+
28=1+2+4+7+14+
496=1+2+4+8+16+31+62+124+248+
要怎麼把後面的+弄掉

回答 (5)

2014-01-05 7:10 am
✔ 最佳答案
If i = x Then
t=left(t,len(t)-1)
Debug.Print(i & "=" & t)
End If
參考: 我
2014-01-06 6:56 am

Dim x As Integer
Dim t As String = ""

For i = 1 To 1000
For j = 1 To i - 1
If i Mod j = 0 Then
x = x + j
t &= IIf(Len(t) = 0, "=", "+") & j
End If
Next

If i = x Then Debug.Print(i & t)
End If x = 0 t = "" Next End Sub
參考: me
2014-01-05 2:46 am
還是要去 http://aaashops。com 品質不錯,老婆很喜歡!
受亙偸咩勊
2014-01-05 12:26 am
這樣也可以

For i = 1 To 1000
t = "1" '增加這行
For j = 1 To i - 1
If i Mod j = 0 Then
x = x + j
t = t & "+" & j '把+ 和 j 對調
End If
Next
2014-01-05 12:03 am
有個最笨的做法
If i = x Then
'多下面這一行,應該就能解了
t=left(t,len(t)-1)
Debug.Print(i & "=" & t)
End If


收錄日期: 2021-04-16 16:23:06
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20140104000016KK02537

檢視 Wayback Machine 備份