Sunday, 1 September 2013

linear search

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace linearSearch
{
   class Program
   {
       static void Main(string[] args)
       {
           int i, value,flag=0;
           Console.WriteLine("enter the number to be searched");
           value = Int32.Parse(Console.ReadLine());


           int[] num = new int[5];

           Console.WriteLine("enter the element's");
           for (i = 0; i < 5; i++)
           {
               num[i] = Int32.Parse(Console.ReadLine());

           }
           
           for (i = 0; i < 5; i++)
           {
               if (num[i] == value)
               {
                   flag = 1;
               }

           }

           if (flag == 1)
           {
               Console.WriteLine("number is in list");
           }

           else
           {
               Console.WriteLine("number is not in the list");
           }
           }
   }

   }

No comments:

Post a Comment