The university of information technology named after Muhammad al-khorazmiy
The student of the group 850-20 of the faculty “Radio and mobile communication”
Laboratory work 6
Performed by: Abdulxayev Elbek
Checked by: Xusan shoraimov
Binar qidirish algoritmidan foydalanib, n ta butun son ichidan siz qidirayotkan son bor yoki yo’qligini tekshiruvchi funksiya tuzing.,shu son bor bo’lsa, joylashgan o’rnini ekranga chiqazing.
Code:
#include
#include
using namespace std;
int main () {
int myints[100],n,s,i,j=0;
cout<<"enter the elemnts of array: ";
cin>>n;
for(int i=0;icin>>myints[i];
}
cout<<"enter the searching num: ";
cin>>s;
int * p;
p = find (myints, myints+n, s);
if (p != myints+n)
cout << "Element found in myints: " << *p << '\n';
else
cout << "Element not found in myints\n";
j = find(myints, myints+n, s) - myints;
cout << s << " was found at index " << j << '\n';
return 0;
}
Do'stlaringiz bilan baham: |