CodeClerks

A BINARY SEARCH PROGRAM TO SEARCH AN ELEMENT FROM A LONG, DIFFICULT TO REMEMBER ARRAY for $5

Level 1
Attention: The owner of this service has not logged into CodeClerks for more than 30 days. It is highly recommend that you contact them before ordering this service. Last Login: 1099 days ago

A BINARY SEARCH PROGRAM TO SEARCH AN ELEMENT FROM A LONG, DIFFICULT TO REMEMBER ARRAY

INSTRUCTIONS ON HOW TO USE THIS PRODUCT
STEPS TO UTILISE THE PRODUCT ARE:-

STEP1->COPY THE SOURCE CODE INTO C++ COMPILATION SOFTWARES ( EXAMPLE:-TURBO C++,VISUAL STUDIO CODE).

STEP2->COMPILE AND RUN THE PROGRAM (AN OUTPUT SCREEN WILL POP UP LIKE BELOW IMAGE).



STEP3->ENTER 10 ELEMENTS(NUMBERS) STRICTLY IN ASCENDING ORDER AND TO DO SO, PRESS ENTER AFTER EACH ELEMENT ENTERED.



STEP4->AFTER ENTERING THE LAST ELEMENT ,PRESS ENTER AND THE MESSAGE (" ENTER ELEMENT TO BE SEARCH") WILL POP UP.

STEP5->ENTER THE VALUE TO BE SEARCHED LIKE IN ABOVE IMAGE AND THEN PRESS ENTER AGAIN.

OUTPUT
IT WILL BE IN THE FORM OF A MESSAGE WITH SYNTAX IN THE FORMAT BELOW:-
"The number, <the element you desired to search> found at position <position of that element in the entered array"


SOURCE CODE
#include<iostream>
using namespace std;
int main(){
int i, arr[10], num, first, last, middle;
cout<<"Enter 10 Elements (in ascending order): ";
for(i=0; i<10; i++)
cin>>arr;
cout<<"\nEnter Element to be Search: ";
cin>>num;
first = 0;
last = 9;
middle = (first+last)/2;
while(first <= last)
{
if(arr[middle]<num)
first = middle+1;
else if(arr[middle]==num) {
cout<<"\nThe number, "<<num<<" found at Position "<<middle+1;
break;
}
else
last = middle-1;
middle = (first+last)/2;
}
if(first>last)
cout<<"\nThe number, "<<num<<" is not found in given Array";
cout<<endl;
return 0;
}


What's included

Source Code

Tags

c

0.0

0 reviews

Rating breakdown


Other services by varunmangla

$5 - In stock