#include
main()
{
int s[10],t,i,j,x;
printf("input 10 numbers:\n");
for(t=0;t<10;t++)
scanf("%d",&s[t]);
for(i=0;i<9;i++)
for(j=0;j<9-i;j++)
if(s[j]>s[j+1])
{t=s[j];s[j]=s[j+1];s[j+1]=t;}
printf("the result is:\n ");
for(j=0;j<10;j++)
printf("%d",s[j]);
printf("\n");
}
任何一本C语言书上都有这个算法。
#define N 10
main( )
{ int a[N];
int i,j,t;
for (i=0; i
for (j=1; j<=N-1; j++)
for (i=0; i
{ t=a[i];a[i]=a[i+1];a[i+1]=t; }
printf("The sorted numbers: \n");
getch();
}