diff --git a/D-Linear-Search/D-Linear-Search.d b/D-Linear-Search/D-Linear-Search.d new file mode 100644 index 0000000..ab1bd9d --- /dev/null +++ b/D-Linear-Search/D-Linear-Search.d @@ -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; +} diff --git a/D-Linear-Search/README.md b/D-Linear-Search/README.md new file mode 100644 index 0000000..80681b6 --- /dev/null +++ b/D-Linear-Search/README.md @@ -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 diff --git a/README.md b/README.md index eedd2dd..80079ca 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/VB.Net-Linear-Search/README.md b/VB.Net-Linear-Search/README.md new file mode 100644 index 0000000..a0a6f74 --- /dev/null +++ b/VB.Net-Linear-Search/README.md @@ -0,0 +1,3 @@ +VB.Net-Linear-Search + +Example Linear Search in VB.Net diff --git a/VB.Net-Linear-Search/VB.Net-Linear-Search.vb b/VB.Net-Linear-Search/VB.Net-Linear-Search.vb new file mode 100644 index 0000000..460e872 --- /dev/null +++ b/VB.Net-Linear-Search/VB.Net-Linear-Search.vb @@ -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