From b19ea5552dfe71bb1c0914aa6b51810198b209ba Mon Sep 17 00:00:00 2001 From: bumsquest Date: Thu, 31 Oct 2019 20:30:25 +0530 Subject: [PATCH] Added Linear Search using CPP. The user enters the range of the array, enters the array elements, enters the number to be searched. Then a linear search is performed for the number to be searched. If found, index is returned, else a "Not found" message is printed. --- Searching/LinearSearch.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Searching/LinearSearch.cpp diff --git a/Searching/LinearSearch.cpp b/Searching/LinearSearch.cpp new file mode 100644 index 0000000..943c79a --- /dev/null +++ b/Searching/LinearSearch.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int n, i, srch, index = -1; + cout<<"\t\tLinear Search Demonstration"; + cout<>n; + int arr[n]; + cout<<"Enter "<>arr[i]; + + cout<<"Enter the element to be searched: "; + cin>>srch; + + for(i = 0; i < n; i++) + { + if (arr[i] == srch) + index = i+1; + } + + if(index == -1) + cout<<"Element "< pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy