作业3
#include <stdio.h>
void main()
{
int
s[15]={3,6,9,10,13,15,19,20,22,23,27,50,80,83,90};
int t,left=0,right=14,mid;
printf("Input the number to find:");
scanf("%d",&t);
while(left<=right)
{
mid=(left+right)/2;
if(s[mid]==t)
break;
else if(s[mid]>t)right=mid-1;
else
left=mid+1;
}
if(s[mid]==t)
printf("%d is the NO.%d\n",t,mid);
else
printf("无此数\n");
}
#include <stdio.h>
void main()
{
int
s[15]={3,6,9,10,13,15,19,20,22,23,27,50,80,83,90};
int t,left=0,right=14,mid;
printf("Input the number to find:");
scanf("%d",&t);
while(left<=right)
{
mid=(left+right)/2;
if(s[mid]==t)
break;
else if(s[mid]>t)right=mid-1;
else
left=mid+1;
}
if(s[mid]==t)
printf("%d is the NO.%d\n",t,mid);
else
printf("无此数\n");
}