Tuesday 17 January 2012

linear search method


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[10],i,num,flag=0;
cout<<"Enter ten numbers in the array"<<endl;
for(i=0;i<10;i++)
{
cin>>arr[i];
}
cout<<"Enter the number to search"<<endl;
cin>>num;
cout<<"The array elements are"<<endl;
for(i=0;i<10;i++)
{
cout<<arr[i]<<endl;
}

// loop to search the number
for(i=0;i<10;i++)
{
if(num==arr[i])
{
flag=1;
cout<<"The number is found at "<<i+1<<" location"<<endl;
break;
}
}
  if(flag==0)
  {
  cout<<"The number is not found"<<endl;
  }


getch();
}

2 comments:

  1. Play The Jackpot city online casino in India
    Jackpot หาเงินออนไลน์ city is one of the most exciting and popular gambling destinations on the deccasino Las Vegas strip. Come celebrate the new year with the latest casino kadangpintar games

    ReplyDelete
  2. Harrah's Ak-Chin Casino & Hotel - Mapyro
    Get 김천 출장샵 directions, reviews and 충주 출장마사지 information for 남양주 출장샵 Harrah's Ak-Chin Casino 전라북도 출장마사지 & Hotel in 보령 출장마사지 Hanover, IN.

    ReplyDelete