hey m a new user so didnt knw it...
nywyas here's the program i made..
/*A PROGRAM TO SEARCH AN ELEMENT IN 1D ARRAY USING BINARY SEARCH USING ITERATION*/
#include<stdio.h>
#include<conio.h>
void binary(int array[],int n,int ele)
{
int beg=0;
int end=n-1;
int mid;
mid=(beg+end)/2;
while((beg<=end)&&(array[mid]!=ele))
{
if(ele>array[mid])
beg=mid+1;
else
end=mid-1;
mid=(beg+end)/2;
}
if(array[mid]==ele)
printf("element found at %d",mid);
else
printf("element not found\n");
}
void main()
{
int array[50],i,ele,n;
clrscr();
printf("the list should be sorted in ascending order\n");
printf("enter the size of array\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",array[i]);
}
printf("enter the element to be searched\n");
scanf("%d",&ele);
binary(array,n,ele);
}
and the output is not right....the position of the item to be searched is cuming out to b wrong..
n showing null pointr assignment..