cpp
#include <stdio.h>
#include <conio.h>
#define INDEX 10
void swap (int *, int *);
int main () {
int a[INDEX];
int x,y;
int beg,end,mid,target;
clrscr();
printf ("Enter 10 numbers:\n\n");
for (x=0;x<INDEX;x++)
scanf ("%d",& a[x]);
for (y=0;y<INDEX;y++)
for (x=0;x<INDEX;x++)
if ( a[x] > a[x+1])
{
swap (&a[x],&a[x+1]); //swap pointer and function//
}
printf ("\nIn Ascending 0rder\n");
for (x=0;x<INDEX;x++)
printf ("%4d",a[x]);
printf ("\n");
beg=0;
end=9;
printf ("\nEnter the number to be searched:");
scanf ("%d", &target);
binarysearch (&beg,&end,&mid)//pointer function
while (beg<end&&a[mid]!=target)
{
mid=(beg+end)/2;
if ( target<=a[mid])
end= mid-1;
else
beg=mid+1;
mid=(beg+end)/2;
}
if (a[mid]==target)
{
printf ("\nThe number is found at position");
printf (" a[%d]",mid);
}
else{
printf ("\n The number is not found.");
}
getch ();
return 0;
}
void swap (int *p,int *q)
{
int temp;
temp=*q;
*q=*p;
*p=temp;
}
***the binary search should be converted into function using pointer. i couldn't make it run, please help. thanks