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

有誰會以下題目的~拜託幫幫我吧!
還有之前有一個人有回答我的問題,可是因為時間到了,被奇摩移除了,我認得你的帳號,可是不知道,如果你有看到的話,回我,我回補你點數的(還有如果會的話麻煩順便幫我解一下題),謝謝

拜託~會幾題就寫幾題~我會想辦法給你們點數的~謝謝

<1>請宣告陣列如下 dim sq(10,10)設計程式輸入方陣數目(例如 4,至少 2 維方陣),輸出如下
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

<2>計算費氏級數(Fibonacci),第一數為1,第二數為1,下一數為前兩數之和,例如輸入9項,則輸出
1 1 2 3 5 8 13 21 34


<3>輸入要排序幾項,例如6項,接著輸入資料,例如11 , 23 , 5 ,9 , 89 , 3
輸出 3 , 5 , 9 , 11 , 23 89

<4>輸入要排序幾項,例如 7 項,接著輸入資料,例如
41 , 63 , 15 , 9 ,79 , 123 , 23 輸出 9 , 15 , 23 , 41 , 63 , 79 , 123


<5> 請寫出一個完整的二元搜尋方程式

2006-12-27 15:13:05 · 1 個解答 · 發問者 ? 1 in 電腦與網際網路 程式設計

抱歉~第三第四題可以幫我分開寫嗎??謝謝

2007-01-01 10:36:01 · update #1

1 個解答

五題全部在裡面
第三四題是同樣的題目 併成一題
第五題得先建立二元樹
所以我改用二分搜尋法
(借用第三四題所建的陣列)

Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, m As Integer, n As Integer
Dim sq(10, 10) As Integer, a(10) As Integer
Dim buf As String

' Q1
For i = 1 To 10
For j = 1 To 10
sq(i, j) = 0
Next j
sq(i, i) = 1
Next i

n = InputBox("印幾層陣列?")
For i = 1 To n
buf = ""
For j = 1 To n
buf = buf & sq(i, j)
Next j
Print buf
Next i

' Q2
n = InputBox("Fibonacci 印到第幾項?")
If (n = 1) Then
Print "1"
ElseIf (n = 2) Then
Print "1 1"
Else
buf = "1 1 "
i = 1: j = 1
For m = 3 To n
k = i + j
i = j: j = k
buf = buf & k & " "
Next m
Print buf
End If

' Q3, Q4
n = InputBox("多少筆資料?")
For i = 1 To n
a(i) = InputBox("第 " & i & " 筆 => ?")
Next i
For i = 1 To n - 1
For j = i + 1 To n
If a(j) < a(i) Then
k = a(i)
a(i) = a(j)
a(j) = k
End If
Next j
Next i
buf = ""
For i = 1 To n
buf = buf & a(i) & ", "
Next i
Print left(buf, len(buf)-2)

' Q5
m = InputBox("搜尋的數是 ?")
i = 1: j = n
Do
k = (i + j) / 2
If (a(k) = m) Then
Exit Do
ElseIf (a(k) > m) Then
j = k - 1
Else
i = k + 1
End If
Loop While (i <= j)
If (i > j) Then
Print "沒有這個數."
Else
Print m & " 在位置 " & k
End If

End Sub

2006-12-28 02:18:34 · answer #1 · answered by JJ 7 · 0 0

fedest.com, questions and answers