从最低到最大打印阵列

时间:2017-10-12 00:53:56

标签: c++ arrays bubble-sort

我正在开发一个项目,用于打印从最小到最大的数字数组。现在我只打印最大的数字。我已经研究了2天,但找不到答案。有人可以告诉我我哪里错了:

#include <iostream>

using namespace std;

int max(double nSalaries[])
{
    double highest = nSalaries[0];

    int index = 0;

    for(int j = 1; j < 10; j++)
    {

        for(int i = 1; i < 10; i++)
        {
            if(nSalaries[i] > highest)
            {
                highest = nSalaries[i];
                index = i;
            }
        }
    }

    cout << "What's the highest?: " << highest << endl;

    nSalaries [index] = 0;

    return 0;
}

int main()
{

    double nSalaries[] = {256, 734, 201, 3, 123, 40, 99, 257, 7, 609};

    cout << max(nSalaries );

    return 0;
}

0 个答案:

没有答案