PROJECT: Binary Search

Learn and Trouble Shoot Problems Related to C-Language here.

PROJECT: Binary Search

Unread postby rajeevmahura » Thu May 22, 2008 6:14 pm

#include<stdio.h>
#include<conio.h>
void main()
{

int beg,end,ub,lb=1,i;
int mid,item,num,data[10];
clrscr();

printf("\n\t\tEnter How Many Numbers Do You Want Enter ");
scanf("%d",&num);

ub=num;

printf("\n\n\t\tPlese Enter Data in Shorting Form \n");
getch();

for(i=1;i<=num;i++)
{
printf("Enter Any Number for data[%d]",i);
scanf("%d",&data[i]);
}

for(i=1;i<=num;i++)
{
printf("\n\t%d",data[i]);
}
printf("\n\n\tEnter The Searching Item ");
scanf("%d",&item);

mid = (lb + ub)/2;

if(item==mid&&item<=mid)
{
for(i=1;i<=mid;i++)
{
if(data[i]==item)
{
printf("Yes %d is Exist at %d Possition",item,i);
}
}
}
else
{
if(item>mid)
{
for(i=mid;mid=='\0';i++)
{
if(data[i]==item)
{
printf("Yes %d is Exist at %d Possition ",item,i);

}
}
}
}

/*if(d==1)
{
printf("No, %d is not Exist in Data ",item);
}*/
getch();
}
--Regards--
Rajeev Mahura
Servers & Storage Professional
http://about.me/rajeevmahura
User avatar
rajeevmahura
 
Posts: 144
Joined: Tue May 20, 2008 5:22 pm
Location: Bangalore | New Delhi
Full Name: Rajeev Mahura
Date Of Birth: 15 Jan 1984
Address: New Delhi
Profession: DOEACC Trainer
DOEACC Center: DOEACC DELHI
Mobile No: 0

Return to C-Language

Who is online

Users browsing this forum: No registered users and 2 guests

cron