Program for search the number using binary search. Gain Infiniti

Program for search the number using binary search.



#include<stdio.h>
#include<conio.h>
main()
{
        clrscr();
                int i,f,l,n,mid,a[20],y;
                printf("\n Enter the sizre of array");
                scanf("%d",&n);
                printf("\n Enter the size of element \n");
                for(i=0;i<n;i++)
                scanf("%d",&a[i]);
                printf("\n Enter the no. to be search");
                scanf("%d",&y);
                f=1;
                l=n;
                mid=(f+l)/2;
                while(f<=l&&a[mid]!=y)
     {
                if(y>a[mid])
                f=mid+1;
                if(y<a[mid])
                l=mid-1;
     }
     if(y==a[mid])
     printf("\n no.is found at position %d",mid+1);
     else
     printf("\n no.is not found");
     getch();
     return 0;
 }

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 

Design By Manish and Ranjan