English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問如果在一個陣列中,
Ex:int a[10]={10,20,30,40,50,60,70,80,90,100}
要插入一個數字,例如35
會printf出10,20,30,35,40,50,60,70,80,90,100
要怎麼把這個程式碼打出來呀?
那如果要刪除一個數字,例如30
printf出10,20,40,50,60,70,80,90,100
要怎麼做呢?
請指教^^

2007-01-09 15:58:04 · 1 個解答 · 發問者 小丸 1 in 電腦與網際網路 程式設計

1 個解答

Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, a(20) As Integer
Dim buf As String
k = 10
buf = ""
For i = 0 To k
a(i) = i * 10
buf = buf & a(i) & " "
Next i
Print "目前的陣列 : " & buf
n = InputBox("請輸入要增加的數")
For i = 0 To k
If n < a(i) Then Exit For
Next i
For j = k To i Step -1
a(j + 1) = a(j)
a(j) = n
Next j
k = k + 1
buf = ""
For i = 0 To k
buf = buf & a(i) & " "
Next i
Print "目前的陣列 : " & buf
n = InputBox("請輸入要刪除的數")
For i = 0 To k
If n = a(i) Then Exit For
Next i
If (i > k) Then
MsgBox "沒有這個數"
Else
k = k - 1
For j = i To k
a(j) = a(j + 1)
Next j
End If
buf = ""
For i = 0 To k
buf = buf & a(i) & " "
Next i
Print "目前的陣列 : " & buf
End Sub
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-01-10 00:25:46 · answer #1 · answered by JJ 7 · 0 0

fedest.com, questions and answers