Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Tuesday, April 20, 2010

The following program is used for linear searchin pf elements in an array. (c++)


The following program is used for linear searchin pf elements in an array. (c++)
 
 
#include< iostream.h>
#include< conio.h>
#include< stdlib.h>
int search;
int flag;
int input(int *,int,int);
void linear_search(int *,int, int);
void display(int *,int);
void main()
{
clrscr();
int number,key, list[200];
number=input(list,number,key);
key=search;
cout<<"\n Entered list as follows: \n";
display(list,number);
linear_search(list,number,key);
cout<<"\nIn the following list\n";
display(list,number);
}
//Defination of function
void linear_search(int l[],int n, int element)
{
int k;
flag=1;
for(k=0;k< n;k++)
{
if(l[k]==element)
{
cout<<"\nSearch is successful \n";
cout<<"\n Element : "<<<" Found at Location: "<< k+1;
> flag=0;
}
}
if(flag)
cout<<"\nSearch is unsuccessful";
}
void display(int list[],int n)
{
int i;
for(i=0;i< n;i++)
{
cout<<<"\t";
}
}
input(int list[], int number,int key)
{
int i;
number=20;
key =30;
cout<<"Number of elements in the list:: "<< number;
for(i=0;i<20;i++)
{
list[i]=rand()%100;
}
cout<<"\nElement to be searched:: "<< key;
search=key;
return number;
}

Related Posts by Categories



0 comments:

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP