The method of dichotomy of C language

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3   4 intSearch (int*a,intkey)5{//binary finds the element of key in the order table, returns 0 if the return element subscript is found6     intlow=0, Mid; 7     intHigh= -; 8      while(low<=High )9     {  TenMid= (Low+high)/2;  One         if(Key==a[mid])returnMid//find the Unknown origin element A         Else if(Key<a[mid]) high=mid-1;//continue searching in the first half of the area -         ElseLow=mid+1;//Find in the second half area -     }   the     return 0;//not found - }   -    - voidMain () + {   -     int*A,key,i;  +     intb[ -]={0};  AA=b;  atprintf"Please enter 20 integers from the largest to the smaller: \ n");  -      for(i=1; i<= -; i++)   -     {   -scanf"%d",&B[i]);  -                -     }   inprintf"\ n");  -printf"Please enter the number you are looking for: \ n");  toscanf"%d",&key);  +    -     if(! Search (A,key)) printf ("the number you are looking for is not in the destination array! \ n");  the     Elseprintf"The number you are looking for is:%d \ n", Search (A,key));  *}

The method of dichotomy of C language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.