GeekCode
798 subscribers
452 photos
3 videos
7 files
942 links
🍁Cyber Security ❤️
🍁Hacking Resources 👨‍💻

Providing knowledge to people's🥀
Nobody gets smaller by sharing knowledge
You can also share your knowledge with us...🙂🙂

📰Promotion/Query - @geekcodevipbot
Download Telegram
BINARY SEARCH

C++
........

#include<iostream>

using namespace std;

int main()
{
int a[100], n, i, beg, end, mid, item;

cout << "Enter No. of Elements : ";
cin >> n;

cout << "\nEnter Elements in Sorted Order :\n";
for (i = 1; i <= n; i++)
{
cin >> a[i];
}

cout << "\nEnter Item you want to Search : ";
cin >> item;

beg = 1;
end = n;

mid = (beg + end) / 2;

while (beg <= end && a[mid] != item)
{
if (a[mid] < item)
beg = mid + 1;
else
end = mid - 1;

mid = (beg + end) / 2;
}

if (a[mid] == item)
{
cout << "\nElement found at location : " << mid;
}
else
{
cout << "Element not found";
}
return 0;
}

========
Output
========

Enter No. of Elements : 3

Enter Elements in Sorted Order :
2
3
5

Enter Item you want to Search : 3

Element found at location : 2
What is C Language?

C is an essential general-purpose computer programming language that supports structural programming, typical machine instructions, recursion, and variables with a static system. Besides, the C programming language allows programmers to handle addresses, bits, and bytes and gives swift control over development.
Dennis M. Ritchie developed the C programming language in 1972 to implement in the UNIX operating system. Initially, programmers used the C language to design systems, primarily the operating systems. It was gradually applied in the compiler, assemblers, text editor, database, utilizer, and more.


Example:

#include<stdio.h>
int main () {
printf (“Hello, geekcode!/n”);
return 0;
}

@geekcode