C语言程序编写——折半查找法答:include<stdio.h>int main(){int a[16]={15,14,13,12,11,10,9,8,7,6,5,4,3,1,0}; int l=0,r=15,mid,x; scanf("%d",&x); do {mid=(l+r)/2; if(a[mid]==x)break; if(x>a[mid])r=mid-1; else l=mid+1; }while(l<=r); if(a[mid]==x) print...
...整数构成的顺序表,根据用户输入的查找值,实现顺序表的顺序查找...答:include<stdio.h> //顺序表就是在计算机内就是数组。define N 10 int search(int a[10],int n); //找到,返回其所在位置,找不到返回-1;int main(){ int a[10]={12,2,16,30,8,28,4,10,20,6};int sa = 28; //查找的数。int sb = 18;int ra = search(a,sa);int rb...
顺序表{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}当用折半查找,查关答://实现过程如下:#include <iostream>using namespace std;int a[]={1,2,3,4,5,5,7,8,9,10,11,12,13,14,15};int b[10];int Binary_Search(int num){ int l=0; int r=14; //最后一个数的下标 int mid; int ans=0; while(l<=r) { mid=(l+r)/2...
...10个整形数据(数据有序,利用折半查找),查找数据是否存在;如果存在...答:include <stdio.h> void main(){ int i,x,a[10],pos,low,high,mid;printf("请按照从小到大的顺序输入数据:\n");for(i=0; i<10; i++){ scanf("%d",&a[i]);} printf("请输入要查找的数据:");scanf("%d",&x);pos=-1;low=0;high=9;do { mid = high+low/2;if(x>a...