The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Linear Search in C++ by...
By Guest on 27th July 2017 05:21:26 PM | Syntax: CPP | Views: 72



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int arr[100];
  6.     int i, loc=0,item, n, k=1;
  7.     cout<<"Enter the value of range: ";
  8.     cin>>n;
  9.     cout<<"Enter the values: "<<endl;
  10.  
  11.     for(i=1; i<=n; i++)
  12.     {
  13.         cin>>arr[i];
  14.     }
  15.  
  16.     /*cout<<"The value of set is: ";
  17.     for(i=0; i<n; i++)
  18.     {
  19.         cout<<arr[i];
  20.     }*/
  21.  
  22.  
  23.     cout<<"Enter the value for searching: "<<endl;
  24.     cin>>item;
  25.  
  26.     while(k<=n && loc==0)
  27.  
  28.     {
  29.         if(item==arr[k])
  30.         {
  31.           loc=k;
  32.         }
  33.         k++;
  34.     }
  35.  
  36.     if (loc==0)
  37.         cout<<"The value is not found."<<endl;
  38.     else
  39.         cout<<"The value is number "<<loc<<endl;
  40.  
  41. }



  • Recent Pastes
  • Coba
    1 day 15 hours 36 mins 35 secs ago
  • Sadasd
    2 days 7 hours 34 mins 29 secs ago
  • Sa
    2 days 7 hours 35 mins 34 secs ago
  • Sdfg
    2 days 8 hours 20 mins 51 secs ago
  • Tytul
    2 days 10 hours 4 mins 57 secs ago