#include<stdio.h>
#include<stdio.h>
int main(){
int i[3] = { 5, 1, 9 };
int m, n, j;
for (m = 0; m < 2; m++) //m<2:第一第二个数排好序后第三个数自动归位
for (n = m + 1; n < 3; n++) //m+1是因为m+1前的数已经是比较好了的数,不用重新比较
{
if (i[m] < i[n]) //值交换
{
j = i[n];
i[n] = i[m];
i[m] = j;
}
}
printf("从大到小输出:\n");
for (j = 0; j < 3; j++)
printf("%d ", i[j]);
system("pause");
return 0;
}
Two for loops and using an if statement, and compares the number of exchanged three