know the personalities
hold your mouse,move left and right

Program to search an element using binary search method


job detailsFree Publishing of valuable information(s) in our website-Procedure to submit detailsjob details

Free Publishing of your College/University function details


Free Publishing of Your College/University function details in our website.Please send details to following email ids


technicalsymposium@gmail.com.
technicalsymposium@in.com.
technicalsymposium@yahoo.com.
technicalsymposium@hotmail.com.
Google Groups

Get Free E-Mail Alerts Daily

Get Daily Job/EntranceExam/Scholarships/
Admission/Competitive Exam Details Symposium/Conference Alerts in your email

Please Enter your email id and go to your inbox and confirm.You will be a member in our group.

Email:
Visit this group

Freshers Jobs/Symposium/Conference/Certification &Education News Given Below-Get Now

Freshers Jobs and IT /Govt Jobs

Symposium and Conference Details

Free Lecture Notes

Free Placement Papers

Free Project Codings


                

program to search an element using binary search method

/* program to search an element using binary search method*/
#include<stdio.h>
void sort(int a[],int n)
{
int i,j,t;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
int search(int a[],int low,int up,int key)
{
/* fn. to search an elt in the list using binary search*/
int mid;
if(low<=up)
{
mid=(low+up)/2;
if(a[mid]==key)
return mid;
else if(a[mid]<key)
return(search(a,mid+1,up,key));
else
return(search(a,low,mid-1,key));
}
else
return -1;
}
void main()
{
int n,i,j=0,a[15];
clrscr();
printf("\n\n\t\tSEARCHING AN ELEMENT USING BINARY SEARCH METHOD\n\n");
printf("\n\tEnter the No. of Elements in the List : ");
scanf("%d",&n);
printf("\n\tEnter the Elements: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i>0 && a[i]<a[i-1]) j=1;
}
if(j)
{
printf("\n\n\tList Not In Sorted Order\n\n");
sort(a,n);
printf("\n\n\tLIST AFTER SORTING :\t");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
printf("\n\n\tEnter the Key to Search : ");
scanf("%d",&i);
j=search(a,0,n-1,i);
if(j==-1)
printf("\n\tSearch Key %d not found ",i);
else
printf("\n\tSearch Key %d found at position %d",i,j+1);
getch();
}

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com