Computer Engineering
الذهاب إلى القناة على Telegram
تمام فایل های مربوط به دروس اینجا گذاشته و ماندگار خواهند بود. گروه @Com_engineering01Gap پی وی @sireh03
إظهار المزيد1 967
المشتركون
-124 ساعات
+57 أيام
+2730 أيام
أرشيف المشاركات
1 967
#include <iostream>
using namespace std;
int binsearch(const int s[], int n, int x) {
int low = 0, high = n - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (x == s[mid])
return mid;
else if (x > s[mid])
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
int main() {
int s[9] = {5, 7, 13, 24, 36, 49, 51, 67, 92};
cout << "Enter x: ";
int x;
cin >> x;
int l = binsearch(s, 9, x);
if (l == -1)
cout << "Not found";
else
cout << "Location: " << l;
return 0;
}
