Home > Back-end > Oj in the school system, always appear the Presentation Error, have know brother help a look
Oj in the school system, always appear the Presentation Error, have know brother help a look
Time:01-21
#include # include
Int main () { Int n, j=1; Int Max, min, temp. The scanf (" % d ", & amp; n); Int * a=(int *) malloc (sizeof (int) * n); For (int I=0; I & lt; n; I++) { The scanf (" % d ", & amp; A [I]); } Min=Max=0; While (j & lt; N) { If (a [j] & gt; A (Max)) Max=j; If (a [j] Min=j; j++; } Temp=a, [0]. A [0]=a/min; A (min)=temp; Temp=a [n - 1); A [n - 1)=a (Max); A (Max)=temp;
For (int I=0; I & lt; N - 1; I++)//then with modified with the output, but the results do wrong answer, I really took Printf (" % d ", a [I]); Printf (" % d ", a [n - 1));
printf("\n");//this line to distinguish a result, the time is not easy to distinguish, upload code
For (int I=0; I & lt; N; I++)//use this output is PE error, I would like to roughly the reason is that there is space behind the last element Printf (" % d ", a [I]); return 0; }
CodePudding user response:
Code is no problem, pay attention to in the last add free (a);//release space
Trouble spots may be your compiler compiler or server is the C language, like the for (int I=0; I & lt; N - 1; I++) that define a local variable in a for loop, general C compilers do not support, is one of the characteristics of C + +,
In view of the above have defined the j, the back of the loop can be used as a loop variable, j
CodePudding user response:
The final output modify try:
for (int I=0; I & lt; n; I++) Printf (" % d % c, "a [I], (i
CodePudding user response:
Above the z more, modify:
for (int I=0; I & lt; n; I++) Printf (" % d % c, "a [I], (i