/*P5.15 Program to search an element through for binary search*/
#include <stdio.h>
#define SIZE 100
int binary_search(int arr[],int item, int low, int high);
main()
{
int arr[SIZE],i, item, n;
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter elements of the array(in sorted order) : \n");
for(i=0; i<n; i++)
scanf("%d",&arr[i]);
printf("Enter the item to be searched : ");
scanf("%d", &item);
i = binary_search(arr,item,0,n-1);
if(i == -1)
printf("Not Present\n");
else
printf("Present at index %d\n", i);
}/*End of main()*/
int binary_search(int arr[],int item, int low, int up)
{
int mid;
if(up < low)
return -1; /*not found*/
mid = (low+up)/2;
if(item > arr[mid])
return binary_search(arr,item,mid+1,up); /*Search in right portion, tail recursive call */
else if(item < arr[mid])
return binary_search(arr,item,low,mid-1); /*Search in left portion, tail recursive call */
else
return mid; /*found*/
}/*End of binary_search()*/
#include <stdio.h>
#define SIZE 100
int binary_search(int arr[],int item, int low, int high);
main()
{
int arr[SIZE],i, item, n;
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter elements of the array(in sorted order) : \n");
for(i=0; i<n; i++)
scanf("%d",&arr[i]);
printf("Enter the item to be searched : ");
scanf("%d", &item);
i = binary_search(arr,item,0,n-1);
if(i == -1)
printf("Not Present\n");
else
printf("Present at index %d\n", i);
}/*End of main()*/
int binary_search(int arr[],int item, int low, int up)
{
int mid;
if(up < low)
return -1; /*not found*/
mid = (low+up)/2;
if(item > arr[mid])
return binary_search(arr,item,mid+1,up); /*Search in right portion, tail recursive call */
else if(item < arr[mid])
return binary_search(arr,item,low,mid-1); /*Search in left portion, tail recursive call */
else
return mid; /*found*/
}/*End of binary_search()*/
Hello! Do you know if they make any plugins to protect against hackers?
ReplyDeleteI'm kinda paranoid about losing everything I've worked hard on.
Any suggestions?
Also visit my website ... natural hemorrhoid treatment
Hi, just wanted to mention, I liked this article. It was helpful.
ReplyDeleteKeep on posting!
my page :: Fashion Jewellery
This is very interesting, You're a very skilled blogger. I've joined
ReplyDeleteyour feed and look forward to seeking more of your excellent post.
Also, I have shared your website in my social networks!
Here is my homepage; Http://Www.Irishmusicassociation.Com
Just want to say your article is as amazing.
ReplyDeleteThe clearness on your put up is simply cool and that i can suppose you're an expert in this subject. Fine along with your permission allow me to clutch your feed to stay updated with coming near near post. Thanks 1,000,000 and please carry on the rewarding work.
Feel free to surf to my blog post :: Dominos 2 For 1 vouchers
Wonderful items from you, man. I have take into accout your stuff
ReplyDeleteprior to and you're simply too great. I really like what you've bought here, really like
what you're stating and the best way through which you assert it. You are making it enjoyable and you continue to care for to keep it sensible. I can not wait to learn far more from you. That is actually a great website.
my blog: Free stuff Uk
What a material of un-ambiguity and preserveness of valuable knowledge
ReplyDeleteconcerning unexpected feelings.
My web site; kitsch jewellery uk
Thanks for the marvelous posting! I certainly enjoyed
ReplyDeletereading it, you will be a great author.I will make sure to bookmark your blog and will eventually come back someday.
I want to encourage you to definitely continue your great work, have a nice weekend!
Here is my web blog dominos promo Codes
It's awesome to go to see this website and reading the views of all colleagues on the topic of this piece of writing, while I am also zealous of getting knowledge.
ReplyDeleteFeel free to surf to my web-site Http://Cms.Egsd.Org:80/Moodle19/User/View.Php?Id=57600&Course=1
Hi, I think your website might be having browser compatibility issues.
ReplyDeleteWhen I look at your website in Ie, it looks fine but when opening in Internet Explorer,
it has some overlapping. I just wanted to give you a quick heads up!
Other then that, fantastic blog!
Feel free to visit my page ... Freebies In Australia
You've made some good points there. I looked on the web for more information about the issue and found most people will go along with your views on this site.
ReplyDeleteMy website - Which android Tablet is the best
Great post. I will be going through some of these issues as well.
ReplyDelete.
Also visit my web blog: best value android tablet
I loved as much as you will receive carried out
ReplyDeleteright here. The sketch is tasteful, your authored material stylish.
nonetheless, you command get bought an shakiness over that you wish be delivering the
following. unwell unquestionably come further formerly again as exactly the same
nearly a lot often inside case you shield this hike.
My page ... care home operations
This is my first time visit at here and i am genuinely impressed to read
ReplyDeleteall at alone place.
My homepage - Care home consultant
There is certainly a lot to find out about this issue.
ReplyDeleteI like all the points you have made.
My web page - fashion Jewellery online
Way cool! Some very valid points! I appreciate you penning this write-up plus the rest of
ReplyDeletethe site is very good.
My web-site :: Dominos Voucher Codes £15
Simply desire to say your article is as surprising.
ReplyDeleteThe clearness on your submit is just nice and that i can think you are
knowledgeable in this subject. Well together with your permission allow
me to seize your RSS feed to stay updated with coming near near post.
Thanks a million and please continue the enjoyable work.
Feel free to surf to my homepage :: developlinks.com
Can I simply just say what a comfort to find somebody that truly
ReplyDeleteunderstands what they are discussing on the net.
You certainly realize how to bring a problem to
light and make it important. More and more people have to look at this and understand this side of the story.
It's surprising you aren't more popular because you surely possess the gift.
My website :: discount code for Domino pizza
Hi there it's me, I am also visiting this website daily, this website is truly fastidious and the people are really sharing fastidious thoughts.
ReplyDeletemy webpage :: cars insurance calculators
Hi there i am kavin, its my first time to commenting
ReplyDeleteanywhere, when i read this post i thought i could also create comment due
to this brilliant article.
Take a look at my homepage dominos 50 off voucher
What's up it's me, I am also visiting this website on
ReplyDeletea regular basis, this web page is genuinely fastidious and the visitors are
truly sharing good thoughts.
Have a look at my weblog: dominos Discounts