Skip to content
This repository was archived by the owner on Dec 29, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions D-Linear-Search/D-Linear-Search.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import std.stdio;
int main(){

int n,x;
int arr[1000];

writeln("Enter the number of elements in array: ");
readf("%d",&n);

writefln("Enter %d integer(s): ",n); // writefln is used to write according to the format of arguments
for(int i = 0; i < n; i++ ){
scanf("%d",&arr[i]);
}

writeln("Enter a number to search");
scanf("%d",&x);

int pos,flag=0;

for( int i = 0; i < n; i++ ){
if( x == arr[i] ){
flag = 1;
pos = i;
break;
}
}

if ( flag == 1 )
writefln("Number found at index: %d",pos);
else
writeln("Number not found");

return 0;
}
8 changes: 8 additions & 0 deletions D-Linear-Search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
On Windows the program can be executed using following command:

> DMD D-Linear-Search.d


On Ubuntu, the program can be executed as:

$ dmd D-Linear-Search.d & ./D-Linear-Search
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ Linear search is a very simple search algorithm. In this type of search, a seque
|16| [Andrew Joshua Loria](https://github.com/ajloria) | University of Washington | United States | Java-7 |
|17| [Jirayu Saengwannakool](https://github.com/bankzxcv) || Thailand | Javascript,Golang |
|18| [Ryan Michalec](https://github.com/a3qz) || United States | F# |
|19| [Soumya Raj Darbari](https://github.com/srd091) || India | VB.Net |
3 changes: 3 additions & 0 deletions VB.Net-Linear-Search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VB.Net-Linear-Search

Example Linear Search in VB.Net
43 changes: 43 additions & 0 deletions VB.Net-Linear-Search/VB.Net-Linear-Search.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Imports System

Public Class Test
Public Shared Sub Main()

Dim n,x,i,pos,flag as Integer
Dim a(1000) as Integer

Console.Write("Enter the number of elements in array: ")
n = Console.ReadLine
Console.WriteLine("{0} ", n)

Console.Write("Enter {0} integer(s): ", n)
for i=0 to n-1
a(i) = Console.ReadLine
next
for i=0 to n-1
Console.Write("{0} ", a(i))
next
Console.WriteLine()

Console.Write("Enter a number to search: ")
x = Console.ReadLine
Console.WriteLine("{0} ", x)

flag=0

for i=0 to n-1
if (x = a(i)) then
flag = 1
pos = i
exit for
end if
next

if (flag = 1) then
Console.WriteLine("Number found at index: {0}", pos)
else
Console.WriteLine("Number not found")
end if

End Sub
End Class