1.累加程式 1+2+4+7+...+106=575
2.累加程式1+2+4+5+7+8+...+100+101=3468
誰能告訴我VB的程式碼
2006-11-24 11:03:33 · 4 個解答 · 發問者 WEI 1 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() Dim I%, X%, T%, S$ I = 1 Do I = X + I: T = T + I X = X + 1: S = S & I & "+" Loop Until I = 106 MsgBox Left(S, Len(S) - 1) & "=" & TEnd SubPrivate Sub Command2_Click() Dim I%, X%, T%, S$ I = 1 Do I = X + I: T = T + I X = IIf(X = 1, 2, 1) S = S & I & "+" Loop Until I = 101 MsgBox Left(S, Len(S) - 1) & "=" & TEnd Sub
2006-11-24 13:31:45 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
Private Sub Form_Activate()
n = Val(InputBox("", "", "106")) '輸入值
For i = 1 To n
Sum = Sum + i
s = s & i & "+"
Next i
Print Sum & " = " & Left(s, Len(s) - 1)
End Sub
----------------------------------------------------------
另類解法高斯法
Private Sub Form_Activate()
n = Val(InputBox("請輸入1加至n", "計算1+...n", "100"))
Print (1 + n) * n / 2
End Sub
2006-11-27 15:45:51 · answer #2 · answered by ? 1 · 0⤊ 0⤋
阿...我以為兩個的規則是一樣的...
2006-11-25 10:54:00 · answer #3 · answered by 以晴 2 · 0⤊ 0⤋
數列的規則 用文字詳述 這樣比較清楚
2006-11-24 12:20:50 · answer #4 · answered by 英凱 2 · 0⤊ 0⤋