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
ඕනම රටකට සෙට් වෙන CV එකක්
ErMurazor
Updated:
Yesterday at 9:50 AM
Hambantota
7 Acres Beachfront Land For Sell DownSouth , PerPerch Price 420 000
1024 Digital
Updated:
Wednesday at 11:57 AM
Baseus PI LITE INDOOR CAMERA
ErMurazor
Updated:
Monday at 12:26 PM
Ad icon
Colombo
Hard Disk For Sale
mazza
Updated:
Oct 10, 2026
land for sale
justasking
Updated:
Oct 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
C Progamming help
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="EKGuest" data-source="post: 28493689" data-attributes="member: 582168"><p>Error එක එන්නේ if...else එක ඇතුලේ mid value එක සෙට් කරනකොට high low මාරු කරලා දාලා තියෙන නිසා. තව ඔතන found වේරියබල් එක අත්යාවශ්ය නැහැ while loop එක ඇතුලේ searchKey එක හම්බුන ගමන් break කලාම හරි.</p><p></p><p>[CODE=c]#include<stdio.h></p><p></p><p>int bSearch(int A[],int low,int high,int searchKey)</p><p>{</p><p> int position=-1;</p><p> int found=0;</p><p> int mid;</p><p></p><p> while(low<=high && !found)</p><p> {</p><p> mid=(low+high) / 2;</p><p> if(A[mid]==searchKey)</p><p> {</p><p> position=mid;</p><p> found=1; // found වේරියබල් එක පාවිච්චි නොකර මෙතන break කරලා ලූප් එකෙන් exit වෙන්න පුලුවන්</p><p> }</p><p> else if(searchKey<A[mid])</p><p> {</p><p> high=mid - 1;</p><p> }</p><p> else</p><p> {</p><p> low=mid + 1;</p><p> }</p><p> }</p><p> </p><p> return position;</p><p>}</p><p></p><p>int main()</p><p>{</p><p> int arr1[]={5,12,23,28,35,42};</p><p></p><p> int key=35;</p><p> int position= bSearch(arr1,0,5,key);</p><p> </p><p> if(position==-1)</p><p> {</p><p> printf("Element is not present");</p><p> }</p><p> else</p><p> {</p><p> printf("Element is present in index %d",position);</p><p> }</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="EKGuest, post: 28493689, member: 582168"] Error එක එන්නේ if...else එක ඇතුලේ mid value එක සෙට් කරනකොට high low මාරු කරලා දාලා තියෙන නිසා. තව ඔතන found වේරියබල් එක අත්යාවශ්ය නැහැ while loop එක ඇතුලේ searchKey එක හම්බුන ගමන් break කලාම හරි. [CODE=c]#include<stdio.h> int bSearch(int A[],int low,int high,int searchKey) { int position=-1; int found=0; int mid; while(low<=high && !found) { mid=(low+high) / 2; if(A[mid]==searchKey) { position=mid; found=1; // found වේරියබල් එක පාවිච්චි නොකර මෙතන break කරලා ලූප් එකෙන් exit වෙන්න පුලුවන් } else if(searchKey<A[mid]) { high=mid - 1; } else { low=mid + 1; } } return position; } int main() { int arr1[]={5,12,23,28,35,42}; int key=35; int position= bSearch(arr1,0,5,key); if(position==-1) { printf("Element is not present"); } else { printf("Element is present in index %d",position); } } [/CODE] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom