Sort foaming method is a bubble sort by : number of adjacent two more, to increase the number of small up front. If there is a Number N, then n-1 time to compare.Comparison of n-1 times in the first 22, n-j 22 in J trip to compare.
code as follow:
// date:2020/3/5
// author:xiezhg5
#include <stdio.h>
int main(void)
{
int a[10];
int i,j,t;
printf("请输入10个数字:\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]); //a[i]储存输入的数字
for(j=0;j<9;j++) //进行9次循环,实现9趟比较
for(i=0;i<9-j;i++) //在每一趟中进行9-j次比较
if(a[i]>a[i+1]) //相邻两个数比较
{
//t是用于交换的中间变量
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
printf("排序后的数字为:\n");
for(i=0;i<10;i++)
printf("%d ",a[i]);
return 0;
}