浮点数组排序问题求解

这是个嵌套函数对浮点数组的选择排序,我不知道为什么会这样,请帮下忙吧,做了一晚上。

img

img

img


源代码和运行结果都在图上,求各位了。感激不尽


#include<iostream>
#include<stdio.h>
using namespace std;
#define SIZE 10
void sort(float a[], int n) {
    int i, j, k;
    float t;
    for (i = 0;i < n;++i) {
        k = i;//没有这句会报错
        for (j = i + 1;j < n;++j) {
            if (a[j] < a[i]) {
                k = j;
            }
        }
        if (k != i) {
            t = a[i];
            a[i] = a[i + 1];
            a[i + 1] = t;
        }
    }
}

int main() {
    void sort(float a[], int n);
    float a[SIZE];
    int i;
    cout << "pls enter 10 float numbers" << endl;
    for (i = 0;i < SIZE;++i) {
        cin >> a[i];
        cout << endl;
    }
    sort(a, SIZE);//这句不能写在上面的for循环里面
    cout << "the sorted numbers:" << endl;
    for (i = 0;i < SIZE;++i) {
        cout << a[i] << " ";
    }
    return 0;
}