排序下面一组数据
23,34,12,26,11,23
#include <stdio.h>
#include <stdlib.h>
#define N 6
int main(int argc, char *argv[])
{
int a[N]={23,34,12,26,11,23},t;
int i,j;
for(i=N-1;i>0;i--)
for(j=0;j<i;j++)
if(a[j]>a[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}
for(i=0;i<N;i++)
printf("%d ",a[i]);
system("PAUSE");
return 0;
}
============
#include <stdio.h> #include <stdlib.h> #define N 6 int main(int argc, char *argv[]) { int a[N]={23,34,12,26,11,23}; int t; int i,j; for(i=N-1;i>0;i--){ for(j=0;j<i;j++) if(a[j]>a[j+1]){ t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for(i=0;i<N;i++){ printf("%d ",a[i]); } system("PAUSE"); return 0; }