There are 15 numbers that are stored in an array from large to small, using the binary lookup method to find out that the number is the value of the first element of the array, and if the number is not in the array, the output "no this number"

Source: Internet
Author: User

//July 22, 2017#include <stdio.h>#defineLEN 15intMain () {intN; voidBinsearch (int* p,intN); intarr[len]={98, the, the, the, the, -, $, Wu, +, the, the, $, *, to, in}; printf ("Please enter the number you want to find: \ n"); scanf ("%d",&N);    Binsearch (Arr,n); return 0;}voidBinsearch (int* p,intN) {    intLow,high,mid; Low=0; High=len-1;  while(low<=High ) {Mid= (Low+high)/2; if(p[mid]==N) {printf ("%d is the value of the%d element of the array (subscript starting from 0) \ n", N,mid);  Break;//Note After the element is found, the loop is ended        }            Else if(p[mid]>n) Low = mid+1; ElseHigh = mid-1; }    if(Low>high) printf ("There is no such number in the array");}

There are 15 numbers that are stored in an array from large to small, using the binary lookup method to find out that the number is the value of the first element of the array, and if the number is not in the array, the output "no this number"

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.