您的位置:首页 >综合知识 >

C语言中二分法的具体程序是什么呢 知道

导读 #include #include //int chashu(int shu,int *a); main() { int chashu(int shu , int p[11] ); int a[11]; int shu; int i; int jieguo; for (i=1;i

#include #include //int chashu(int shu,int *a); main() { int chashu(int shu , int p[11] ); int a[11]; int shu; int i; int jieguo; for (i=1;i<=10;i++) {printf("请输入第%d个数",i); scanf("%d",&a[i]); } printf("这是你输入的数"); for (i=1;i<=10;i++) printf("%d",a[i]); printf("请输入你要查找的数"); scanf("%d",&shu); jieguo=chashu(shu,a); if ( jieguo!=0 ) printf("所查找的数在第%d个",jieguo); else printf("你所查找的数不存在!!"); } int chashu(int shu, int p[11]) {int x1=1; int x2=10; int x0; int t; t=0; x0=(x1+x2)/2; do { if (shu==p[1]) {t= 1; break;} else if (shu==p[10]) {t= 10; break;} else if (p[x0]>shu) {x1=x1; x2=x0; t=0; x0=(x1+x2)/2; } else if (p[x0]=p[1]... #include #include //int chashu(int shu,int *a);main(){int chashu(int shu , int p[11] ); int a[11];int shu;int i;int jieguo;for (i=1;i<=10;i++){printf("请输入第%d数",i);scanf("%d",&a[i]);}printf("输入数");for (i=1;i<=10;i++)printf("%d",a[i]);printf("请输入要查找数");scanf("%d",&shu);jieguo=chashu(shu,a);if ( jieguo!=0 ) printf("所查找数第%d",jieguo); else printf("所查找数存"); }int chashu(int shu, int p[11]){int x1=1;int x2=10;int x0;int t;t=0;x0=(x1+x2)/2;do{ if (shu==p[1]) {t= 1;break;}else if (shu==p[10]) {t= 10;break;}else if (p[x0]>shu) {x1=x1; x2=x0; t=0; x0=(x1+x2)/2; } else if (p[x0]=p[1]);if (t !=0 ) return t;else return 0;} 展开

免责声明:本文由用户上传,如有侵权请联系删除!

Baidu
map