سورس کد جستجوی ترتیبی (sequential search)
دوشنبه, ۲۴ آذر ۱۳۹۳، ۰۸:۵۶ ب.ظ
//azarprogrammer.blog.ir
#include<iostream>
#include<conio.h>
using namespace std;
void seqsearch(int x,int s[])
{
int location=0;
while(location<=20&&s[location]!=x)
location++;
if (location>20)
cout<<"Not found";
else
cout<<"Place is : "<<location+1;
}
int main()//azarprogrammer.blog.ir
{
int x,s[20];
cout<<"Enter 20 numbers"<<endl;
for(int i=0;i<20;i++)
{
cout<<"number "<<i+1<<" :";
cin>>s[i];
}
cout<<"enter the search number :";
cin>>x;
seqsearch(x,s);
getch();
return 0;
}
//azarprogrammer.blog.ir
۹۳/۰۹/۲۴