你这只是把最大的数排在了最后面,你可以搜下冒泡排序.
#include <iostream>
using namespace std;
int main()
{
int a[]={0,87,35,1485,79,46,4185};
int max = a[0],i = 0, j = 0;//i,j用来记录序号,将未排列的最大数记未a[0]
for(i = 0;i < 7;i++)
for(j = 0;j < 6-i; j++)
{
int change;
if(a[j] > a[j+1])
{
change = a[j];
a[j] = a[j+1];
a[j+1] = change;
}
}
for(i = 0; i < 7; i++)
{
cout<<a[i]<<endl;
}
}
#include <iostream>
using namespace std;
int main()
{
int a[]={0,87,35,1485,79,46,4185};
int max = a[0],i = 0, j = 0;//i,j用来记录序号,将未排列的最大数记未a[0]
for(i = 0;i < 7;i++)
for(j = 0;j < 6-i; j++)
{
int change;
if(a[j] > a[j+1])
{
change = a[j];
a[j] = a[j+1];
a[j+1] = change;
}
}
for(i = 0; i < 7; i++)
{
cout<<a[i]<<endl;
}
}