#include<iostream.h>
#include<conio.h>
#include<time.h>
#include<dos.h>
int main()
{ clock_t start,end;
start=clock();
clrscr();
int a[10],n,ele,pos;
cout<<"Enter size of array: ";
cin>>n;
cout<<"\nEnter Array: ";
for(int i=0;i<n;i++)
{ cin>>a[i]; }
cout<<"\nEnter The Element To Be Searched: ";
cin>>ele;
for(i=0;i<n;i++)
{ if(a[i]==ele)
{ cout<<"\nElement Found At Positon: "<<i+1;
break; }
if(i==n-1)
{ cout<<"\nElement Not Found In Given Array !!!";
} }
delay(200);
end=clock();
cout<<"\nTime Taken Is: "<<(end-start)/CLK_TCK;
getch();
return 0;
}
#include<conio.h>
#include<time.h>
#include<dos.h>
int main()
{ clock_t start,end;
start=clock();
clrscr();
int a[10],n,ele,pos;
cout<<"Enter size of array: ";
cin>>n;
cout<<"\nEnter Array: ";
for(int i=0;i<n;i++)
{ cin>>a[i]; }
cout<<"\nEnter The Element To Be Searched: ";
cin>>ele;
for(i=0;i<n;i++)
{ if(a[i]==ele)
{ cout<<"\nElement Found At Positon: "<<i+1;
break; }
if(i==n-1)
{ cout<<"\nElement Not Found In Given Array !!!";
} }
delay(200);
end=clock();
cout<<"\nTime Taken Is: "<<(end-start)/CLK_TCK;
getch();
return 0;
}
http://techcpp.blogspot.in/2016/04/program-to-implement-linear-search.html
ReplyDelete