程序目的是通过排序算法进行数组由大到小排序 但不同编译器运行结果不一致
#include <iostream>
#include <iomanip> //使用setw()函数
using namespace std;//定义无参函数
void bubble(int[], int);
int main()
{
int arry[10] = {11, 4, 55, 6, 77, 8, 9, 0, 7, 1};
cout << "排序前:";
for(int i=0;i<10;++i)
{
cout << arry[i] << setw(3);
}
cout << endl;
bubble(arry, 10);
return 0;
}
void bubble(int a[], int n)
{
for(int i=1;i<n;++i) //排序函数
{
for(int j=0;j<n-i;++j)
{
if(a[j]<a[j+1])
{
int temp;
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
cout << "排序后:"; //输出
for(int i=0;i<n;++i)
{
cout << a[i] << setw(5);
}
}
codeblocks
dev C++