Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Program to Implement Linear Search in CPP (C plus plus)

Program to implement Linear Search in CPP (C plus plus)

In this tutorial, we will learn about Program to implement Linear Search in CPP (C plus plus).

#include<iostream>
 
using namespace std;
 
int main()
{
    int array[20];
	int val;
	int k;
	int i;
	int j=0;
	
    cout<<"Please enter the number of values you want to enter: ";
    cin>>val;
    
    cout<<endl<<"Please enter the values into the array"<<endl;
    
    for(i=0;i<val;++i)
        cin>>array[i];
    
    cout<<endl<<"Please enter value to search: ";
    cin>>k;
    
    for(i=0;i<val;++i)
    {
        if(array[i]==k)
        {
            j=1;
            break;
        }
    }
    
    if(j)
        cout<<endl<<"Value found at position "<<i+1;
    else
        cout<<endl<<"Value not found";
        
    return 0;
}

Output:

Program to implement Linear Search in CPP (C plus plus)

Program to implement Linear Search in CPP (C plus plus)

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.