【C语言】将输入的10个数排序
代码:
#include <stdio.h> int main() { int a[10], t; int i, j, max; printf("请输入10个数:\n"); for (i = 0; i <= 9; i=i+1) scanf_s("%d", &a[i]);/*循环输入10个数字*/ for (j = 9; j >=0; j = j-1) { max = j; for (i = 0; i <=j; i = i + 1) { if (a[max] <= a[i]) max = i; if (max != j) { t = a[max]; a[max] = a[j]; a[j] = t; } } } for (i = 0; i <= 9; i=i+1) printf("%-3d", a[i]); }
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/11930333.html