BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Visual Programming (http://bzupages.com/237-visual-programming/)
-   -   Program for Linear Search in an Array VB Code (By Sheraz) (http://bzupages.com/f237/program-linear-search-array-vb-code-sheraz-7193/)

.BZU. 15-12-2009 11:06 PM

Program for Linear Search in an Array VB Code (By Sheraz)
 
Code:

  Module Module1
 
      Sub Main()
          Dim ar As Integer()
          Dim flag As Integer = 0
          Dim to_search As Integer
          ar = New Integer() {15, 8, 1, 6, 34, 7, 5, 342, 4, 7}
 
          Console.WriteLine("Please enter the integer that you want to search")
          to_search = Console.ReadLine()
 
          For i = 0 To ar.GetUpperBound(0)
              If to_search = ar(i) Then
                  flag = 1
                  Exit For  'Optional, to exit from loop when condition is true first time
              End If
 
          Next
 
          If flag = 1 Then
              Console.Write("The element {0} exists in the array", to_search)
          Else
              Console.Write("The element {0} doesn't exist in the array", to_search)
          End If
          Console.ReadLine()
 
      End Sub
 
  End Module

 



All times are GMT +5. The time now is 05:39 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.