Home > Back-end >  For help, the c language
For help, the c language

Time:09-25

 # include & lt; Stdio. H> 
Void main () {
Int a, [3].
//char c;
Int I, num, mid, flag, legal, m, n, top, bott;
Int sign=0;//said there was no find the digits
Num=0;

Printf (" please input array: ");
The scanf (" % d ", & amp; A [0]);
I=1;
While (I & lt; 3) {
The scanf (" % d ", & amp; A [I]);
If (a [I] Printf (" \ n the input number is less than a number on, please input again is greater than the value of a number: ");
}
The else
i++;
}
Printf (" input array is: ");
for(i=0; i <3; I++) {
Printf (" % d ", a [I]);
}
printf("\n");
Flag=1;
//mid=15/2;
Mid=0;
Top=0;
Bott=14;
Legal=0;
While (flag) {
char c;
Printf (" please enter a search number: ");
The scanf (" % d ", & amp; Num);
M=(num & lt; A [0]);
N=(num & gt; A, [2]).
If ((num & lt; A [0]) | | (num & gt; A [2]))//is outside the scope of this score
Legal=1;
Sign=0;
Top=0;
Bott=3;
While (sign==0 & amp; & (top & lt;=bott)) {
Mid=+ bott (top)/2;
If (num & gt; A (mids))
Top=mid + 1;
Else if (num & lt; A (mids))
Bott=mid - 1;
The else {
Printf (" % d is the first % d a element of the array of values ", num, mid);
break;
Sign=1;
}


}

if(! Sign | | legal==1)
Printf (" without this number, \ n ");
//char c;
Printf (" whether or not to input (Y/N) ");
The scanf (" % c ", & amp; C);
If (c=='Y')
Flag=1;
The else
flag=0;
}

}


Why every time I perform to "whether or not to enter", then I can't input, jump straight to flag=0, and then exit the cycle???????

CodePudding user response:

Please reply to

CodePudding user response:

Printf (" whether or not to input (Y/N) ");
fflush(stdin);//try to empty the keyboard input buffer
The scanf (" % c ", & amp; C);

CodePudding user response:

You give blocked the char c

CodePudding user response:

refer to the second floor u010165006 response:
printf (" whether or not to input (Y/N) ");
fflush(stdin);//try to empty the keyboard input buffer
The scanf (" % c ", & amp; C);

I tried, I can't

CodePudding user response:

The
reference 3 floor m_merelyyang response:
you give blocked the char c

I also think so, how to solve

CodePudding user response:

I put the void main () to int main () on the DEVC++ compiled under didn't you say the problem, and you have a problem of algorithm

CodePudding user response:

if(! Sign | | legal==1)
Printf (" without this number, \ n "); It seems to be out of question anyway show no such number

CodePudding user response:

Printf (" the first % d % d is in the array element values \ n ", num, mid + 1);
Sign=1;
break;
For such then void main () to int main ()
Printf (" the first % d % d is in the array element values \ n ", num, mid); To printf (" the first % d % d is in the array element values \ n ", num, mid + 1);
With respect to OK
  • Related