Int main ()
{
,4,9,5,0,2 int a [6]={10};
Int I, j, m, temp;
for(i=1; i<6; I++)
{
M=a, [I].
For (j=I - 1; J>=0; J -)
{
If (a [j] & gt; M)
{
Temp=a, [I].
A [I]=a, [j].
A [j]=temp;
}
}
}
for(i=0; i<6; I++)
{
Printf (" % d ", a [I]);
}
return 0;
}
CodePudding user response:
Exchange before using a [j] and a [I] is not correct, if you want to move the 3 to 6, 7, 637 for the first time, the second time than is 6 and 7, logic is a little problemCodePudding user response:
You have a logical problem so your method is wrong!Below is the sorting code I wrote for reference ~
#include
Int main ()
{
,4,9,5,0,2 int a [6]={10};
Int I, j, temp.
for(i=0; i<6; I++)
{
for(j=i+1; J<6; J++)
If (a [I] & gt; A [j])
{
Temp=a, [I].
A [I]=a, [j].
A [j]=temp;
}
}
for(i=0; i<6; I++)
Printf (" % d ", a [I]);
return 0;
}
CodePudding user response: