Sunday, 12 June 2016

C++ Program of Binary search in Array

In this program we will learn how to search a number from indexes of array.
The code is given below.

//Code Starts
#include <iostream>
#include<conio.h>

using namespace std;

int main()

{
int n,a[n],search,j;

cout<<"Enter Size of Array : ";
cin>>n;

for(int i=0;i<n;i++)
{
cout<<"Enter "<<i<<" element = ";
cin>>a[i];
}

for(int b=0;b<n;b++)

{
cout<<"Number at index ["<<b<<"] = ";
cout<<a[b]<<endl;
}

cout<<"Enter Number to search : ";
cin>>search;

for(int j=0;j<n;j++)

{
if(search==a[j])
{
cout<<"Number found at index : "<<j<<endl;
break;
}
}
getch();
}
//Code Ends

OUTPUT:



Share:

Related Posts:

0 comments:

Post a Comment