# Linear Search Algorithm Source Code in C++

## Linear Search Algorithm in C++ with Source Code

### Linear Search:

What Linear search is what do you think is the importance of a search searches in C++ are of two types one is a linear search and the other is a binary search we learn about linear search. Linear search for a simple example lets us consider an integer array of 5 with 5 elements in it and let the elements be 3 5 9 8 and 16. Now, what is a linear search just like a simple search a Linear search is the one where we start with this beginning element and we check for the required element? Entered by the user and keep incrementing the array index. C++ projects for beginners with source code

Value let us see how it’s done suppose the user has mentioned the array elements as 3 5 9 8 and 16. Now he’s asking us where is element 8 stored in the array. We can find this out by using the linear search as the value entered by the user is 8.

The computer must check from the starting element of the array that is an of 0 that is 3 in 3 equal to 8. Now it goes to the next element is 5 equal to 8 no is 9 no, Finally, it reaches an of three is eight equal to eight yes bingo it must return us with the index with the position of the number entered by the user.

The user wanted the number eight & eight is present in the fourth location of the array that is an of three not to forget there starts with an of zero. That the computer has found out where the position of the number wanted by the user is it must return as the value. Now let us write a simple logic just to get the value and it’s just the core logic it’s not the entire program and gun right it’s going to be something like this if X equal to equal to eight 8 is the value entered by the user.

While okay if you are scanning the value entered by the user say you have scanned. The value entered by the user into a variable called Y you can use supposed to write if x equal to equal to Y fine. if X equal to equal to Y we print F percentile D what’s the position of is the fourth position. It’s going to be I plus one if you have declared the array a of I now to get a clear concept of this. We need a for loop and this is the Core Logic pathway that now returns us the value where the entrance is the position where our required element. Top 5 Programming Languages

#### Code:

#include <iostream>
#include <conio.h>

using namespace std;

void main()
{
int arr[100];
int key,
ar_value, i;
int found =
-1;

cout<<“Enter Array Value. “; cin>>ar_value;
cout<<“\nEnter Any “<>arr[i];
}
cout<<“\nEnter Find Value. “; cin>>key;
for(i = 0; i < ar_value; i++)

{
if (key == arr[i])
{
found = i;
break;
}
}
if (found == -1)
{
}
else
{
cout<<“\nValue found at “<<found<<” index.”;
}
getch();
}

``````#include
#include

using namespace std;

void main()
{
int arr[100];
int key, ar_value, i;
int found =-1;

court<<"Enter Array Value. ";
cin>>ar_value;
court<<"\nEnter Any "<>arr[i];
}
cout<<"\nEnter Find Value. ";
cin>>key;
for(i = 0; i < ar_value; i++)
{
if (key == arr[i])
{
found = i;
break;
}
}
if (found == -1)
{
``` Output: Top 40 projects with C++ for beginners in 2021 The C Programming Language Structure with C Language data types Best Top 5 Programming Languages demand in 2021 C# Projects with Source Code C# windows form application projects with source code (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ```
``` ```
``` Post navigation ← Previous PostNext Post → 2 thoughts on “Linear Search Algorithm Source Code in C++” Pingback: Binary Search Algorithm in C++ with Source Code Pingback: Write an Assembly Language Program to Display a String Leave a Comment Your email address will not be published. Required fields are marked *Type here..Name* Email* Website Save my name, email, and website in this browser for the next time I comment. Δdocument.getElementById( "ak_js_1" ).setAttribute( "value", ( new Date() ).getTime() ); ```
``` ```
``` Search for: Recent Posts What is HTML: Is it a Programming Language? Arizona State University Computer Science Ranking Is coding better than programming? Top 5 Real-World Coding Examples That Save the Day 5 Best Computer Programming Languages for Beginners <br /> (adsbygoogle = window.adsbygoogle || []).push({});<br /> <br /> (adsbygoogle = window.adsbygoogle || []).push({});<br /> ```
``` ```
``` (adsbygoogle = window.adsbygoogle || []).push({}); Privacy Policy Disclaimer Contact Us About Us Write for us    Copyright © 2024 www.codeboks.com - All Rights Reserved. ```
``` var astra = {"break_point":"921","isRtl":"","is_scroll_to_id":"","is_scroll_to_top":"","is_header_footer_builder_active":"1"}; var PT_CV_PUBLIC = {"_prefix":"pt-cv-","page_to_show":"5","_nonce":"ca0affc384","is_admin":"","is_mobile":"","ajaxurl":"https:\/\/www.codeboks.com\/wp-admin\/admin-ajax.php","lang":"","loading_image_src":"data:image\/gif;base64,R0lGODlhDwAPALMPAMrKygwMDJOTkz09PZWVla+vr3p6euTk5M7OzuXl5TMzMwAAAJmZmWZmZszMzP\/\/\/yH\/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgAPACwAAAAADwAPAAAEQvDJaZaZOIcV8iQK8VRX4iTYoAwZ4iCYoAjZ4RxejhVNoT+mRGP4cyF4Pp0N98sBGIBMEMOotl6YZ3S61Bmbkm4mAgAh+QQFCgAPACwAAAAADQANAAAENPDJSRSZeA418itN8QiK8BiLITVsFiyBBIoYqnoewAD4xPw9iY4XLGYSjkQR4UAUD45DLwIAIfkEBQoADwAsAAAAAA8ACQAABC\/wyVlamTi3nSdgwFNdhEJgTJoNyoB9ISYoQmdjiZPcj7EYCAeCF1gEDo4Dz2eIAAAh+QQFCgAPACwCAAAADQANAAAEM\/DJBxiYeLKdX3IJZT1FU0iIg2RNKx3OkZVnZ98ToRD4MyiDnkAh6BkNC0MvsAj0kMpHBAAh+QQFCgAPACwGAAAACQAPAAAEMDC59KpFDll73HkAA2wVY5KgiK5b0RRoI6MuzG6EQqCDMlSGheEhUAgqgUUAFRySIgAh+QQFCgAPACwCAAIADQANAAAEM\/DJKZNLND\/kkKaHc3xk+QAMYDKsiaqmZCxGVjSFFCxB1vwy2oOgIDxuucxAMTAJFAJNBAAh+QQFCgAPACwAAAYADwAJAAAEMNAs86q1yaWwwv2Ig0jUZx3OYa4XoRAfwADXoAwfo1+CIjyFRuEho60aSNYlOPxEAAAh+QQFCgAPACwAAAIADQANAAAENPA9s4y8+IUVcqaWJ4qEQozSoAzoIyhCK2NFU2SJk0hNnyEOhKR2AzAAj4Pj4GE4W0bkJQIAOw=="}; var PT_CV_PAGINATION = {"first":"\u00ab","prev":"\u2039","next":"\u203a","last":"\u00bb","goto_first":"Go to first page","goto_prev":"Go to previous page","goto_next":"Go to next page","goto_last":"Go to last page","current_page":"Current page is","goto_page":"Go to page"}; var wpdata = {"object_id":"1846","site_url":"https:\/\/www.codeboks.com"}; var AICP = {"ajaxurl":"https:\/\/www.codeboks.com\/wp-admin\/admin-ajax.php","nonce":"cf3dc779e5","ip":"54.174.101.64","clickLimit":"2","clickCounterCookieExp":"3","banDuration":"7","countryBlockCheck":"No","banCountryList":""}; var gglcptch_pre = {"messages":{"in_progress":"Please wait until Google reCAPTCHA is loaded.","timeout":"Failed to load Google reCAPTCHA. Please check your internet connection and reload this page."},"custom_callback":""}; var gglcptch = {"options":{"version":"v2","sitekey":"6Ldw65MbAAAAAJKJILs4K1BLBkm09GHGnZL5L927","error":"<strong>Warning<\/strong>:&nbsp;More than one reCAPTCHA has been found in the current form. Please remove all unnecessary reCAPTCHA fields to make it work properly.","disable":1,"theme":"dark"},"vars":{"visibility":false}}; /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+\$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)\$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1); ```