This repository has been archived by the owner on Dec 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from manavmehra96/linearsearch-c#
c# for linear search algo
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
||
} |