0% found this document useful (0 votes)
29 views

Linear Searching Algorithm

The document describes the linear search algorithm and provides code to implement it in C++. It initializes an array, takes user input for array elements and a search value, then iterates through the array comparing each element to the search value and printing the index if it finds a match. The sample output shows it successfully finding and printing the position of the search value in the array.

Uploaded by

princeji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Linear Searching Algorithm

The document describes the linear search algorithm and provides code to implement it in C++. It initializes an array, takes user input for array elements and a search value, then iterates through the array comparing each element to the search value and printing the index if it finds a match. The sample output shows it successfully finding and printing the position of the search value in the array.

Uploaded by

princeji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

LINEAR SEARCHING ALGORITHM

INTRODUCTION:
ALGORITHM:
o
o
o
o
o

Initialize the array a[100]


declare the variables n and x
Give the inputs to the array
Get the searching element (x)
If a[i]==x then print the position of the searching element

PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
int array[100], n, x;
cout<<*********************************
<<This program is to implement linear search algorithm\n
<<*************************************
cout<<Enter how many numbers you are going to enter::;
cin>>n;
cout<<Now enter your elements ::\n;
for(int i=;i<=n;i++)
cin>>array[i];
cout<<Enter the number to be searched ::;
cin>>x;
for(int i=;i<=n;i++)
{
if(array[i]==x)
{
cout<<found at location::<<i <<endl;
break;
}
}
getch();
}

SAMPLE OUTPUT
**************************************...
This program is to implement linear search algorithm
**************************************
Enter how many numbers you are going to enter::5
Now enter your elements ::
1.1

1.2
1.3
1.4
1.5
Enter the number to be searched ::1.5
found at position ::5

You might also like