diff --git a/README.md b/README.md index cfe0fb0..f783e04 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,4 @@ Linear search is a very simple search algorithm. In this type of search, a seque |20| [Marco Wang](https://github.com/aesophor) | University of Taipei | Taiwan | Java, C, Bash, Python-3 | |21| [Grzegorz Wcisło](https://github.com/grzegorz-wcislo) | | Poland | | |22| [Ivan Dyominov](https://github.com/dyominov) | | Ukraine | Scala | +|23| [Pranav Bhardwaj](https://github.com/pranav1999) | Maharaja Surajmal Institute | India | VB.NET | diff --git a/vb-linear-search/README.md b/vb-linear-search/README.md new file mode 100644 index 0000000..aa13880 --- /dev/null +++ b/vb-linear-search/README.md @@ -0,0 +1,3 @@ +# vb-linear-search + +Open file in Visual Studio as console application and run the code. diff --git a/vb-linear-search/vb-linear-search.vb b/vb-linear-search/vb-linear-search.vb new file mode 100644 index 0000000..567cede --- /dev/null +++ b/vb-linear-search/vb-linear-search.vb @@ -0,0 +1,43 @@ +Module LinSearchFunc + + Sub Main() + Console.WriteLine("Linear Searching using Function") + Console.WriteLine() + Dim n, i, k, item As Integer + Console.Write("Enter Number of Elements: ") + n = CInt(Console.ReadLine) + Dim arr(n) As Integer + Console.WriteLine() + For i = 0 To n - 1 + Console.Write("Enter Element(" & (i + 1) & "): ") + arr(i) = CInt(Console.ReadLine) + Next + Console.WriteLine() + Console.WriteLine("Before Sorting") + Console.WriteLine() + For i = 0 To n - 1 + Console.WriteLine("Element in (" & i & "): " & arr(i)) + Next + + Console.WriteLine() + Console.Write("Enter the Element to be searched:") + item = CInt(Console.ReadLine()) + k = linear_search(arr, n, item) + Console.WriteLine() + If k <> -1 Then + Console.WriteLine("Element is Found") + Else + Console.WriteLine("Element is Not Found ") + End If + Console.ReadLine() + End Sub +function linear_search(byval x() as integer,byval y as integer,byval z as integer) + Dim j As Integer + For j = 0 To y - 1 + If x(j) = z Then + Return j + End If + Next + Return -1 + End Function +End Module