/*linear search in an array list
by sanjay kumar singh,ggsestc*/
#include<iostream.h>
#include<conio.h>
#define size 15
void main()
{
int ar[size],n,i,val,flag=0;
cout<<"\t\tLinear search in array list\n\n";
cout<<"Enter the no of elements : ";
cin>>n;
cout<<"Enter elements of the array :\n ";
for(i=0;i<=n-1;i++)
cin>>ar[i];
cout<<"Entered elements are : \n";
for(i=0;i<=n-1;i++)
cout<<ar[i]<<"\t";
cout<<"\nEnter the element u want to search : \n";
cin>>val;
for(i=0;i<n;i++)
{
if(val==ar[i])
{
flag=1;
break;
}
}
if(flag=1)
cout<<"search successful ad its position is at : "<<i+1;
else
cout<<"Search unsuccessful";
getch();
}
by sanjay kumar singh,ggsestc*/
#include<conio.h>
#define size 15
void main()
{
int ar[size],n,i,val,flag=0;
cout<<"\t\tLinear search in array list\n\n";
cout<<"Enter the no of elements : ";
cin>>n;
cout<<"Enter elements of the array :\n ";
for(i=0;i<=n-1;i++)
cin>>ar[i];
cout<<"Entered elements are : \n";
for(i=0;i<=n-1;i++)
cout<<ar[i]<<"\t";
cout<<"\nEnter the element u want to search : \n";
cin>>val;
for(i=0;i<n;i++)
{
if(val==ar[i])
{
flag=1;
break;
}
}
if(flag=1)
cout<<"search successful ad its position is at : "<<i+1;
else
cout<<"Search unsuccessful";
getch();
}
No comments:
Post a Comment