【C语言】用指针描述数组,实现选择法排序
#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); 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/11973012.html