#include <cstdlib>
#include <iostream>
using namespace std;
int LinearSearch (int a[], int x,int n)
{
for(int i=0;i<n;i++)
if(a[i]==x) return i;
return-1;
}
int main(int argc, char *argv[])
{
int a[10];
int i,j,n=10;
for (i=0; i<n; i++)
{
a[i]=rand()%100;
cout<<a [i]<<" ";
}cout<<endl;
LinearSearch(a,0,10);
int x;
cin>>x;
int s = LinearSearch(a,x,n);
cout<<s;
system("PAUSE");
return EXIT_SUCCESS;
}
Админ Ээгий
No comments:
Post a Comment