linear search algorithm c# code example
Example 1: linear search c#
static int LineSearch(int[] numbers, int num)
{
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] == num)
{
return i;
}
}
return -1;
}
Example 2: linear search algorithm c#
static int LineSearch(int[] n,int num) {
for(int i = 0; i < n.Length; i++)
if(n[i] == num) return i;
return -1;
}