Home > Back-end >  Where is the c language subject to solve error, why 90 is not an array, it is in.
Where is the c language subject to solve error, why 90 is not an array, it is in.

Time:09-16

Programming implementation USES bubble sort method with one dimensional integer array of 12 array element array [12]={,52,35,12,58,78,90,587,21,0, 96-65106} according to the sorting sorted from big to small, the output array, before and after sorting and find whether the 90 in the array, if the array, the output 90 position in the array, otherwise output "90 not in the array array", requirement: use Pointers in function realization of sorting, and search functions, in the main function calls these two functions,

#include
#include
# define N 12
Int main ()
{
An int array [N]={,52,35,12,58,78,90,587,21,0, 96-65106};
Int * PTR, I;
Printf (" sorted before the array is: \ n ");
For (PTR=array; PtrPrintf (" % 5 d * PTR);
Int temp.
for(i=0; IFor (PTR=array; PtrIf (* ptr<+ 1) * (PTR)
{
Temp=* PTR.
* PTR=* (PTR + 1);
* (PTR + 1)=temp;
}
Printf (" \ n sorted array is: \ n ");
For (PTR=array; PtrPrintf (" % 5 d * PTR);
printf("\n");
system("pause");
An int array [N].
Int x=90;
Int the location;
Int bottom=0;
Int top=N - 1;
Int mid;
Int flag=0;
While (bottom<=top)
{
Mid=(bottom and top)/2;
If (array (mids)==x)
{
Location=mid;
Flag=1;
break;
}
Else if (array (mids) & gt; X)
Top=mid - 1;
The else
Bottom=mid + 1;
}
If (flag==0)
Printf (" does not exist! \n");
The else
Printf (" % d position in the array is: % d \ n ", x, the location + 1);
system("pause");
return 0;
}

CodePudding user response:

system("pause"); Behind, you declare an array, the array should be put in front of you it sorted array blocked, so you're quite so in an uninitialized array, 90 must be found,
  • Related