July 15, 2024
c-program c ++

Program for Linear Search

This article describes how to perform Linear search in C/C++? Let us discuss about linear search.

What is Linear Search?
Linear search or sequential search is a method for finding a particular value in a list by checking every one of its elements until the desired one is found. Every element is searched one at a time and in sequence. It is the simplest search algorithm. t is a special case of brute-force search.
This searching algorithm is not efficient for large number of element. For large element we can use binary search or hashing.

Searching is one of the important mechanism in computer programming. It plays a good role to make a program slow or fast based on choice appropriate searching mechanism.


C ++ Program for Linear Search

int main(){
int n,i,loc;
float data[100],item;

cout<<”     ”  This Program will show  linear search. “”<<endl<<endl;

cout<<“How many number’s ?. Give a integer number.”<<endl;

if(n<0) {
cout<<“Negatve number is not allow, Please give a integer number.”<<endl;
goto xx;

cout<<“What are the elemnents ?. Give some data.”<<endl;

cout<<“What is the data that you want to search ?. Givea a number.”<<endl;

else loc=0;

cout<<“You have given the following data.”<<endl;
cout<<data[i]<<”  “;

cout<<“Yoy have given “<<item<<” to search from the above data.”<<endl;
cout<<“Searching result :”<<endl;

if (loc==0)
cout<<item<<” is not present here. “;

cout<<item<<” is present here and it’s psition is : “<<loc;


Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

Leave a Reply

Your email address will not be published. Required fields are marked *