diff --git a/Searching/Linear Search/linear_searh.cpp b/Searching/Linear Search/linear_searh.cpp new file mode 100644 index 0000000..c3d20b9 --- /dev/null +++ b/Searching/Linear Search/linear_searh.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; + +int search(vector arr, int n, int x) +{ + int i; + for (i = 0; i < n; i++) + if (arr[i] == x) + return i; + return -1; +} + +// Driver code +int main() +{ + vector arr; + int n; + int x; + cout<<"Enter the number of elements in input : "; + cin>>n; + for(int i=0;i>p; + arr.push_back(p); + } + cout<<"Enter the value to be searched: "; + cin>>x; + int index = search(arr, n, x); + if (index == -1) + cout << "Element is not present in the array"; + else + cout << "Element found at position " << index; + + return 0; +}