Void main ()
{
15,34,6,27,48,4,20 int a [7]={}, I, j, k, t;
Printf (" before sorting sequence: ");
for(i=0; i<7. I++)
Printf (" % 5 d, "a [I]);
for(i=0; i<7. I++)
{k=I;
for(j=i+1; J<7. J++)
If (a [j] & gt; A [k]) k=j;
if(k!=I) t=a, [k]. a[k]=a[i]; A [I]=t; }
Printf (" \ n from big to small sorted (select) \ n ");
for(i=0; i<7. I++)
Printf (" % 5 d, "a [I]);
printf("\n");
}
CodePudding user response:
Modified as follows, for reference:# include
Void main ()
{
15,34,6,27,48,4,20 int a [7]={}, I, j, k, t;
Printf (" before sorting sequence: ");
for(i=0; i<7. I++)
Printf (" % 5 d, "a [I]);
for(i=0; i<7-1; I++)
{
k=i;
for(j=i+1; J<7. J++)
If (a [j] & gt; A [k]) k=j;
if(k!=I)
{
T=a, [k].
a[k]=a[i];
A [I]=t;
}
}
Printf (" \ n from big to small sorted (select) \ n ");
for(i=0; i<7. I++)
Printf (" % 5 d, "a [I]);
printf("\n");
}
CodePudding user response:
# include
//void main ()
Int main ()
{
15,34,6,27,48,4,20 int a [7]={}, I, j, k, t;
Printf (" before sorting sequence: ");
for(i=0; i<7. I++)
Printf (" % 5 d, "a [I]);
for(i=0; i<7. I++)
{
k=i;
for(j=i+1; J<7. J++)
If (a [j] & gt; A [k])
K=j;
# if 0
if(k! I)={
T=a, [k]. a[k]=a[i]; A [I]=t;
}
# the else
If (k!=j)
T=a [k], a [k]=[I], a [I]=t;
# endif
}
Printf (" \ n from big to small sorted (select) \ n ");
for(i=0; i<7. I++)
Printf (" % 5 d, "a [I]);
printf("\n");
return 0;
}
For your reference ~
A little curly braces, or by a comma instead of a semicolon;
CodePudding user response:
You of the inner for loop in the second if part of an exchange of the three statements with curly braces, it is a wholeif(k! I)={
T=a, [k]. a[k]=a[i]; A [I]=t;
}
CodePudding user response: