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;
}