Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #16 from manavmehra96/linearsearch-c#
Browse files Browse the repository at this point in the history
c# for linear search algo
  • Loading branch information
ayan-b authored Oct 16, 2017
2 parents e69de8d + 5e0b269 commit 02ec5e3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions linear search.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;

namespace forgetCode
{
class Program
{
public static void Main()
{
int[] a = new int[100];
Console.WriteLine("Enter number of elements you want to hold in the array ?");
string s = Console.ReadLine();
int x = Int32.Parse(s);

Console.WriteLine("\n Enter array elements \n");
for (int i = 0; i < x; i++)
{
string s1 = Console.ReadLine();
a[i] = Int32.Parse(s1);
}

Console.WriteLine("Enter Search element\n");
string s3 = Console.ReadLine();
int x2 = Int32.Parse(s3);
for (int i = 0; i < x; i++)
{
if (a[i] == x2)
{

Console.WriteLine("Search successful");
Console.WriteLine("Element {0} found at location {1}\n", x2, i + 1);
return;
}
}
Console.WriteLine("Search unsuccessful");
}
}

}

0 comments on commit 02ec5e3

Please sign in to comment.