C语言排序基础---冒泡排序
#include<stdio.h>
#define N 1000
int main()
{
int a[N]={0},i,j,n,t;
printf("please input the length of the list:\n");
scanf("%d",&n);
printf("please input the member of the list:\n");
for(i=0;i<n;i++) /*输入*/
scanf("%d",&a[i]);
for(i=0;i<n;i++)
for(j=0;j<n-1-i;j++) /*依次查找最大的元素存到最后一位*/
{
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
printf("after sort of the list is:\n");
for(i=0;i<n;i++) /*输出*/
printf("%d ",a[i]);
printf("\n");
return 0;
}