? 發問時間： 電腦與網際網路程式設計 · 1 0 年前

# 救救我~~~~我要vb得程式碼.......超急

A...從1到輸入值的總和....(用計數迴圈設計)

B...從1到輸入值的奇數和....(用前測試迴圈設計)

C...從1到輸入值的偶數和....(用後測試回圈設計)

### 3 個解答

• ?
Lv 6
1 0 年前
最佳解答

一.

Private Sub Command1_Click()

Dim i As Integer, temp As String

temp = "54321"

For i = 1 To 5

Print Space(10 - i); Mid(temp, 1, i)

Next i

End Sub

二.

'(A)

Dim i As Long, Total As Long

For i = 1 To Val(InputBox("輸入值"))

Total = Total + i

Next i

Print "1到輸入值的總和...."; Total

'(B)

Dim keyin As Long, i As Long, Total As Long

i = 1

Total = 0

keyin = Val(InputBox("輸入值"))

Do While i < keyin

Total = Total + i

i = i + 2

Loop

Print "1到輸入值的奇數和...."; Total

'(C)

Dim keyin As Long, i As Long, Total As Long

i = 0

Total = 0

keyin = Val(InputBox("輸入值"))

Do

i = i + 2

Total = Total + i

Loop Until i = keyin

Print "1到輸入值的偶總和...."; Total

三.

http://myweb.hinet.net/home9/afuchai/VB/20060101.f...

• 匿名使用者
1 0 年前

第一題的程式碼

a\$ = "54321"

i = 0

For i = 1 To 5

Print Space(10 - i);

Print Left(a\$, i);

Print

Next i

參考資料： 學習中的我
• 1 0 年前

喔, 好