冒泡排序数组s[]的元素,从大到小。
for(int i=1;i!=n;i++) //外层循环
{
for(int j=0;j!=n-i;j++) //内层循环
{
if(s[j] {
temp=s[j]; //符合条件,交换
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
#include
int a[20];
void bubblesort(int a[],int n)
{
int i,j;
int temp;
for(i=0;i
for(j=n-1;j>i;j--)
if(a[j] {
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
void main()
{
int i,n,max=0;
cout<<"input the number n:"<
cout<<"input the numbers a[i]:"<
bubblesort(a, n);
for(i=0;i
希望能帮到你