April 3, 2008

《程式設計》循序搜尋法

 ☆~★~☆~★~☆
 《 循 序  搜 尋 法 》
 ☆~★~☆~★~☆




《程式畫面》
  
    

                        


《程式碼》

Private Sub Command1_Click()
Dim A(1 To 5), b As Long

A(1) = 2
A(2) = 5
A(3) = 9
A(4) = 13
A(5) = 18


n = Val(InputBox(("請輸入1~20的整數"), "輸入數字"))
b = 0

  For i = 1 To 5
 
         
          If n = A(i) Then
                b = 1
          End If
         
        

         If b = 1 Then
                 msg = "找到了你所要搜尋的數字:" & n
         Else
                    b = 0
                 msg = "搜尋不到你所輸入的數字唷! "
         End If
 

Next i


MsgBox msg, , "搜尋結果"
End Sub



Private Sub Command2_Click()
End
End Sub


《作法》
  

循序搜尋法


設定五個定值,

1開始搜尋,

直到 n才結束程式。

假如輸入的n是定值中的其中之一,

則顯示為找到

如果直到 n都沒有找到,

則在Msgbox中顯示為  沒有找到,之後結束。




《心得》 

只能說這只是個半調子的程式,

沒有難度......

又是充版面! 

0推薦此文章
Today's Visitors: 0 Total Visitors: 59
Personal Category: ┬科展專用覽┴★〞 Topic: technology
歷史上的今天:
[Trackback URL]

Reply
  • 1樓

    1樓搶頭香

    Sealed

  • Sealed at December 17, 2012 02:28 PM comment
Post A Comment









Yes No





誰來收藏
Loading ...
unlog_NVPO 0