Loading...
SCE
Home
AI Assistant
Ask Anything
Categories
Python
C#
C++
C
Visual Basic
Java
JavaScript
HTML
CSS
SQL
Git
VIEW ALL
Other
Tags
What's Hot
Featured
I'm Feeling Lucky
Latest
SCE
Loading...
Sign Up
Log In
Binary in c++ (edited)
Posted by
JanWan
Last Updated:
September 19, 2012
#include<iostream>
using namespace std;
int main(void)
{
//Declaration of variables
int array[10];
int i, j, N, temp, keynum;
int low, mid, high;
cout<<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;
cout<<"\t\t@ @"<<endl;
cout<<"\t\t@ Binary @"<<endl;
cout<<"\t\t@ @"<<endl;
cout<<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;
cout<<endl<<endl;
cout<< "Enter the value of N" << endl;
cin>> N;
cout<< "Enter the elements one by one" << endl;
for(i=0; i<N; i++)
{
cin>> array[i];
}
//Bubble sorting begin
for(i=0; i<N; i++)
{
for(j=0; j< (N-i-1); j++)
{
if(array[j] > array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
cout<< "sorted array is..."<< endl;
for(i = 0; i < N; i++)
{
cout<< ""<<endl <<array[i]<<endl;
}
cout<< "Enter the element to be search"<<endl;
cin>> keynum;
//Binary searching begins
low = 1;
high = N;
do
{
mid = (low + high)/2;
if (keynum < array[mid])
high = mid - 1;
else
if(keynum > array[mid])
low = mid + 1;
} while (keynum != array[mid] && low <= high); //End of do-while loop
if (keynum == array[mid])
{
cout << "SUCCESSFUL SEARCH" <<endl;
}
else
{
cout<< "Search is FAILED " <<endl;
}
return 0;
}
J.W.
Production
Related Content
How do you use the BINARY_CHECKSUM function to generate a hash value for a binary data?
PaulAnd
|
Jun 21, 2024
How do you use the BINARY data type to store binary data?
MaryJns
|
Jul 11, 2024
Decimal to Binary in C++
Samath
|
Dec 26, 2014
How do you check if a string contains only binary characters in Python?
TinaGrn
|
Aug 14, 2024
Python Convert Decimal to Binary or Binary to Decimal
Samath
|
Jan 09, 2017
Binary Search Tree in C++
Samath
|
Jan 07, 2021
How to add and retrieve record in a binary file using C++
Samath
|
Jan 06, 2021
C program that takes as input a positive fractional number and converts it to binary
Samath
|
Jan 01, 2017
C program that takes a non- negative integer number as input and prints its binary representation
Samath
|
Jan 01, 2017
C program that takes a 2 digit hexadecimal number and display it in binary format
Samath
|
Jan 01, 2017
Binary to Decimal Conversion in C#
Samath
|
Jan 10, 2021
How do you handle BLOB data (Binary Large Objects) in SQL?
NickCrt
|
Jun 22, 2024
How do you use the IMAGE data type to store large binary data?
AliceWk
|
Jun 06, 2024
Write a Python function to convert a decimal number to binary.
CarolTh
|
Aug 29, 2024
How do you convert a binary number to a decimal number in Python?
IreneSm
|
Aug 31, 2024