Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
Cam ෂෝ කරන්න ආස කෙල්ලෝ
vip video seller srilanka
Updated:
46 minutes ago
Cam show job
vip video seller srilanka
Updated:
Today at 2:01 AM
Vip විඩීයෝ තියේ හොරෙන් රෙකෝඩ් කරපුවා
vip video seller srilanka
Updated:
Today at 1:26 AM
Kandy
Welcome all my all new pet shop Bark.lk
dilumrane
Updated:
Monday at 12:26 PM
Windows RDP Only Rs.500 a month
Blogerwiki
Updated:
Sunday at 12:41 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
A Thread for Programmers.!
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="hasiwebmail" data-source="post: 7825771" data-attributes="member: 21500"><p>//Program to illustrate binary search</p><p>#include<iostream.h></p><p>#include<conio.h></p><p></p><p>class binarysearch()</p><p>{</p><p></p><p>void main()</p><p>{</p><p>int a[100],i,loc,mid,beg,end,n,flag=0,item;</p><p>clrscr();</p><p>cout<<"How many elements ";</p><p>cin>>n;</p><p>cout<<"Enter the element of the array"<<endl;</p><p>for(i=0;i<=n-1;i++)</p><p>{</p><p>cin>>a<em>;</em></p><p><em>}</em></p><p><em>cout<<"Enter the element to be searching ";</em></p><p><em>cin>>item;</em></p><p><em>loc=0;</em></p><p><em>beg=0;</em></p><p><em>end=n-1;</em></p><p><em>while((beg<=end)&&(item!=a[mid]))</em></p><p><em>{</em></p><p><em> mid=((beg+end)/2);</em></p><p><em> if(item==a[mid])</em></p><p><em> {</em></p><p><em> cout<<"search is successfull"<<endl;</em></p><p><em> loc=mid;</em></p><p><em> cout<<"Position of the item "<<loc+1;</em></p><p><em> flag=flag+1;</em></p><p><em> }</em></p><p><em> if(item<a[mid])</em></p><p><em> end=mid-1;</em></p><p> <em>else</em></p><p><em> beg=mid+1;</em></p><p><em>}</em></p><p><em>if(flag==0)</em></p><p><em>{</em></p><p><em>cout<<"search is not successfull";</em></p><p><em>}</em></p><p><em>getch();</em></p><p><em>}</em></p><p><em></em></p><p><em>/*The output of the above program is:</em></p><p><em>How many elements 6</em></p><p><em>Enter the element of the array</em></p><p><em>11</em></p><p><em>22</em></p><p><em>33</em></p><p><em>44</em></p><p><em>55</em></p><p><em>66</em></p><p><em>Enter the element to be searching 44</em></p><p><em>search is successfull</em></p><p><em>Position of the item 4 */</em></p><p><em></em></p><p><em>using borland TC 3.0v</em></p><p><em>verified</em></p></blockquote><p></p>
[QUOTE="hasiwebmail, post: 7825771, member: 21500"] //Program to illustrate binary search #include<iostream.h> #include<conio.h> class binarysearch() { void main() { int a[100],i,loc,mid,beg,end,n,flag=0,item; clrscr(); cout<<"How many elements "; cin>>n; cout<<"Enter the element of the array"<<endl; for(i=0;i<=n-1;i++) { cin>>a[i]; } cout<<"Enter the element to be searching "; cin>>item; loc=0; beg=0; end=n-1; while((beg<=end)&&(item!=a[mid])) { mid=((beg+end)/2); if(item==a[mid]) { cout<<"search is successfull"<<endl; loc=mid; cout<<"Position of the item "<<loc+1; flag=flag+1; } if(item<a[mid]) end=mid-1; else beg=mid+1; } if(flag==0) { cout<<"search is not successfull"; } getch(); } /*The output of the above program is: How many elements 6 Enter the element of the array 11 22 33 44 55 66 Enter the element to be searching 44 search is successfull Position of the item 4 */ using borland TC 3.0v verified[/i] [/QUOTE]
Insert quotes…
Verification
Asuwa dahayen wadi kalama keeyada?
Post reply
Top
Bottom