Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LinearSearchProper
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
  10.             int index = -1;
  11.             int i = 0;            
  12.             Console.WriteLine("Please enter your search term:");
  13.             int searchterm = Convert.ToInt32(Console.ReadLine());
  14.  
  15.             for (i = 0; i <= a.Length - 1; i++)
  16.             {
  17.                 if (a[i] == searchterm)
  18.                 {
  19.                     index = i;
  20.                     break;
  21.                 }
  22.  
  23.             }
  24.            
  25.             Console.WriteLine("Item was found at: " + index);
  26.             Console.ReadLine();
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement