From 8705b0c9f40a76d446c5d494c64996f1eb0c45d6 Mon Sep 17 00:00:00 2001 From: Meetzanonymous <30690468+Meetzanonymous@users.noreply.github.com> Date: Mon, 14 Oct 2019 16:37:53 +0530 Subject: [PATCH] Create binary using method.cpp Binary search Code for cpp --- binary using method.cpp | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 binary using method.cpp diff --git a/binary using method.cpp b/binary using method.cpp new file mode 100644 index 0000000..1ab7ff3 --- /dev/null +++ b/binary using method.cpp @@ -0,0 +1,50 @@ +#include + +using namespace std; + +int main() +{ + int search(int [],int,int); + int n,i,a[100],e,res; + cout<<"How Many Elements:"; + cin>>n; + cout<<"\nEnter Elements of Array in Ascending order\n"; + + for(i=0;i>a[i]; + } + + cout<<"\nEnter element to search:"; + cin>>e; + + res=search(a,n,e); + + if(res!=-1) + cout<<"\nElement found at position "<a[m]) + f=m+1; + else + l=m-1; + } + + return -1; +} \ No newline at end of file