C++ program to implement linear search

/* Write a program to implement linear search */

#include 
using namespace std;

int main() {

   cout <> size;
   const int s = size;

   int a[s];

   cout << "Enter values for array..." << endl;
   for (int i=0; i<s; i++) {
     cout << "a[" << i <> a[i];
   }

   cout << endl;
   cout <> n;

   bool found = false;

   cout << endl;
   cout << "Value found at: ";

   for (int i=0; i<s; i++) {
     if (a[i] == n) {
       cout << i << "  ";
       found = true;
     }
   }

   if (!found)
     cout << "Value not found.";

   return 0;
}

Advertisements