Home > database >  Differential problems appeared some mistakes, please, help to analysis and provide a solution.
Differential problems appeared some mistakes, please, help to analysis and provide a solution.

Time:10-04

Purpose is: requirement sequence input number 15 (can have the same number), then enter a number, to find whether the number in the number 15, is the output of its location, not the output cannot be found, determine to complete a number to choose whether or not to continue on to the next number,
Below is I wrote the original program, there are two problems: 1, regardless of the number in it or not, are unable to display cannot find and difficult to determine the independent choice directly on to the next number, 2, once the number 15 in the same number, enter the number to look up all show that cannot be found,
Pointed out the mistake, can help to analyze, and provide solution,
#include
# pragma warning (4996) disable:
# define N 15
Int main ()
{
Int a [N], I, number, top, bott, mid, loca, sign=0, flag=1;
char c;
Printf (" enter % d sorted Numbers: \ n ", n);
The scanf (" % d ", & amp; A [0]);
I=1;
While (i{
The scanf (" % d ", & amp; A [I]);
If (a [I] {
Printf (" the data is worning worked, both please enter again: \ n ");
}
i++;
}
While (flag=1)
{
Printf (" \ ninput number to look for: ");
The scanf (" % d ", & amp; Number);
Top=0; Bott=N - 1;
If (number & gt;=a [top] & amp; & Number & lt;=a [bott])
While ((top & lt;=bott) & amp; & (sign=0))
{
Mid=+ bott (top)/2;
If (number==a (mids))
{
Loca=mid + 1;
Printf (" has found % d, its position is % d \ n ", number, loca);
Sign=1;
}
Else if (number & lt; A [mid]) bott=mid - 1;
The else top=mid + 1;
}
The else loca=1;
If (sign==0 | | loca==1)
Always find a printf (" % d. \ n ", number).
Printf (" the continue or not (Y/N)?" );
The scanf (" % c ", & amp; C);
If (c=='N' | | c=='N') flag=0;
}
return 0;
}
  • Related