一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>//声明排序函数sort;
void sort(int a[], int n);int main()
{//初始化变量值;int i, a[10];//填充数组;printf("请输入10个整数\n");for (i = 0; i < 10; i++){//获取;printf("第%d个数:", i + 1);scanf("%d", &a[i]);}//输出数组;printf("排序前\n");for (i = 0; i < 10; i++){//输出;printf("%d\t", a[i]);}//换行;printf("\n");//调用sort函数;sort(a, 10);//输出结果;printf("排序后\n");for (i = 0; i < 10; i++){//输出;printf("%d\t", a[i]);}return 0;
}//实现sort函数;
void sort(int a[], int n)
{//初始化变量值;int i, j, k, t;//循环判断;for (i = 0; i < n - 1; i++){//赋值;k = i;//判断;for (j = i + 1; j < n; j++){//比较;if (a[j] < a[k]){k = j;}}//替换;t = a[k];a[k] = a[i];a[i] = t;} }