下列程序中,函数find_data在已从小到大排序好的数组中寻找指定数data,采用二分查找算法,找到则返回该数组元素地址,找不到返回NULL。请填空将程序补充完整。#include [input=type:blank,size:4][/input]find_data(float *a,int n ,float data){ [input=type:blank,size:4][/input]; low=0; high=n-1; while(low<=high) { mid=(low+high)/2; if(a[mid]>data) high=mid-1; else if(a[mid]
举一反三
- 若输入52<;CR>;,则下面程序的运行结果是。main(){int a[8]={6,12,18,42,46,52,67,73};int low=0,mid,high=7,x;printf("Input a x:");scanf("%d",&x);while(low<;=high){mid=(low+high)/2;if(x>;a[mid]) low=mid+1;else if(x<;a[mid]) high=mid-1;else break;}if(low<;=high) printf("Search Successful! The index is:%d\n",mid);else printf("Can't search!\n");}
- 写输出结果#include "stdio.h"int binary(int x, int a[], int n){ int low=0,high=n-l,mid; while(low<=high) { mid=(low+high)/2; if(x>a[mid]) high=mid-l; else if(x<a[mid]) low=mid+l; else return(mid); } void main(){ static int a[]={4,0,2,3,1}; int i,t,j; for(i=1;i<5;i++) t=a[i]; j=i-l; while(j>=0 && t>a[j]) { a[j+1]=a[j]; j--;} a[j+1]=t; } printf("%d\n",binary(3,a,5)); }
- 下面程序用于计算f,n)=1+2++n,其中power(m,n)求m”。请填写程序中相应语句。[br][/br]include <stdio.h>[br][/br]int power(int m,int n){[br][/br]int i;[br][/br][input=type:blank,size:4][/input];for(i=1;i<=n;i+)[br][/br][input=type:blank,size:4][/input];return p;}int f(int k,int n)[br][/br]{[br][/br]int i[br][/br][input=type:blank,size:4][/input];for(i=1;i<=n;i++)[br][/br][input=type:blank,size:4][/input];return s;}int main(void)[br][/br]{intk,n;[br][/br]scanf"%d%d",&k,&n);[br][/br]printf“f(%d,%d)-%ld”,k,n,fk,n);[br][/br]return 0;[br][/br]}[br][/br]
- 若输入52,则下面程序的运行结果是 。 main() {int a[8]={6,12,18,42,46,52,67,73}; int low=0,mid,high=7,x; printf("Input a x:"); scanf("%d",&x); while(low<=high) {mid=(low+high)/2; if(x>a[mid]) low=mid+1; else if(x Search Successful! The index is:5
- 程序填空题,根据下列各题题意,将程序补充完整下列程序输出6至10000之间的亲密数对#include<stdio.h> void main(){ int a,b,c,i; for(a=6;a<=10000;a++) { b=1; for(i=2;i<=a/2;i++) if([input=type:blank,size:4][/input]) b+=i; [input=type:blank,size:4][/input]; for(i=2;i<=b/2;i++) if(b%i==0) c+=i; if([input=type:blank,size:4][/input]&&a!=b) printf("%d %d\n",a,b); } }