C语言程序二次输入时,显示不该现实的的语句,代码都没问题,不知道哪有问题
程序代码:
#include<stdio.h> #define N 15 int main() { int i,number,top,bott,mid,loca,a[N],flag=1,sign; char c; printf("enter date:\n"); scanf("%d",&a[0]); i=1; while(i<N) { scanf("%d",&a[i]); if(a[i]>=a[i-1]) i++; else printf("please enter another number:\n"); } printf("\nAll fifteen numbers are:\n"); for(i=0;i<N;i++) printf("%5d",a[i]); printf("\n"); while(flag) { printf("please input a number to look for:\n"); scanf("%d",&number); sign=0; //sign为0表示未找到 top=0; bott=N-1; if((number<a[0])||(number>a[N-1])) loca=-1; //loca为-1表示找不到 while((!sign)&&(top<=bott)) { mid=(top+bott)/2; if(number==a[mid]) { loca=mid; printf("Has found %d,It's location is %d.\n",number,loca+1); sign=1; } else if(number<a[mid]) bott=mid-1; else top=mid+1; } if(!sign||loca==-1) printf("Can't find %d.\n",number); printf("Continue or not?(Y/N)\n"); scanf("%c",&c); if(c=='n'||c=='N') flag=0; } return 0; }
printf("Continue or not?(Y/N)\n");
出现这一条时printf("please input a number to look for:\n");这一条也会跟着出现,之后后面也有类似问题,请问为什么