[求助]运行是死循环,怎么改呀!
题目:查找任意手输的一维数组中其中一个的位置!# include <stdio.h>
# define N 15
main()
{ int a[N];
int i,num,mid,flag,first,last,loca;
char c;
printf("Enter number:\n");
scanf("%d",&a[0]);
for(i=1;i<N;)
{scanf("%d",&a[i]);
if (a[i]>=a[i-1])
i++;
else
printf("Enter this number again: ");
}
printf("\nthese numbers: ");
for(i=0;i<=N-1;i++)
printf("%4d",a[i]);
printf("\n");
for(flag=1;flag;)
{ printf("input number of look for : ");
scanf("%d",&num);
first=0;
last=N-1;
if((num<a[0])||(num>a[N-1]))
loca=-1;
while(first<=last)
{ mid=(first+last)/2;
if(num==a[mid])
{ loca=mid;
printf("find %d, position is %d \n",num,loca+1);
}
else if (num<a[mid])
last=mid-1;
else
first=mid+1;
}
if(loca==-1)
printf("%d is not find.\n",num);
printf("continue or not(y/n)?");
scanf("%c",&c);
if(c=='n')
flag=0;
}
}