上程序
数组排序,从大到小:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int code[10]={20,3,4,5,60,7,8,9,6,1};
int i;
int box,box_1;
int max,j=0;
box=code[0];
for(j=0;j<9;j++)
{
for(i=0;i<(9-j);i++)
{
if(code[i]<code[i+1])
{
box=code[i+1];
code[i+1]=code[i];
code[i]=box;
}
}
}
for(i=0;i<=9;i++)
{
printf("index%d=%d\n",i,code[i]);
}
return 0;
}
冒泡排序主体
for(j=0;j<9;j++)
{
for(i=0;i<(9-j);i++)
{
if(code[i]<code[i+1])
{
box=code[i+1];
code[i+1]=code[i];
code[i]=box;
}
}
}