Here is a sample program that I wrote using C# to demonstrate linear or sequential search. What does the program will do is to ask the user to give a number which represents an element and then our program will search the given number or element from a list of values stored in our one dimensional array if the given number is there or not.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.
Sample Program Output
Program Listing
linear.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Linear_Search
{
static void Main(string[] args)
{
int flag = 0;
int[] arr = { 5,6,7,8,9,10,11,12,13,14,15};
int num=0;
Console.WriteLine("\tLinear Search in C# ");
Console.WriteLine("\n");
Console.WriteLine("Created By Mr. Jake R. Pomperada");
Console.WriteLine("\n\n");
Console.Write("Enter element to be search : ");
num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n\n");
for (int i = 0; i < 11; i++)
{
if (arr[i] == num)
{
Console.WriteLine(num + " element is found in the list");
Console.WriteLine("\n\n");
flag = 1;
}
else
{
Console.WriteLine("Searching element form the list.");
Console.WriteLine("\n\n");
}
if (flag == 1) break;
}
if (flag == 0)
{
Console.WriteLine("\n\n");
Console.WriteLine(num + " Not Found in the list.");
}
Console.Write("\n\n");
Console.Write("\t Thank You For Using This Software.");
Console.ReadKey();
}
}
}