第1个回答 2015-06-11
#include <iostream.h>
int a[20];
void bubblesort(int a[],int n)
{
int i,j;
int temp;
for(i=0;i<n-1;i++)
{
for(j=n-1;j>i;j--)
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
void main()
{
int i,n,max=0;
cout<<"input the number n:"<<endl;;
cin>>n;
cout<<"input the numbers a[i]:"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
bubblesort(a, n);
for(i=0;i<n;i++)
cout<<" "<<a[i];
cout<<endl;
}
希望能帮到你