Home > Back-end >  Help me to look at the results of this program is what is wrong
Help me to look at the results of this program is what is wrong

Time:10-22

/* pointer method are used to achieve the ascending order of 10 number */
#include
Void main ()
{void swap (int * (p1, p2 int *);
Int I, n, j, k, a, [100].
Int * p;
P=a;
Printf (" input num: ");
The scanf (" % d \ n ", & amp; N);
for(i=0; iThe scanf (" % d ", p++);
for(j=0; j{if (a [j] & gt; + 1 a [j]) swap ((p + j) and (p + j + 1)); }
for(k=0; kPrintf (" % d \ n ", a [k]);
Getch ();
}

Void swap (int * (p1, p2 int *)
{int p;
P=* p1; * p1=* (p2); * the p2=p;
}

CodePudding user response:

Sorting, dual cycle at least

CodePudding user response:

Cycle to write wrong

CodePudding user response:

A single ranking results for loop must be not correct

CodePudding user response:

for(j=0; j{if (a [j] & gt; + 1 a [j]) swap ((p + j) and (p + j + 1)); }
This a loop, you can only make the smallest row in the front, plus a cycle in the loop, with respect to OK
For (I=0; I & lt; N - 1; I++)
{
for(j=0; J & lt; N; J++)
{
If (a [j] & gt; A [m + 1])
Swap ((p + j) and (p + j + 1));
}
}
  • Related