起泡法排序(数组方法).c

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;
}
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值