`
375809600
  • 浏览: 150588 次
  • 来自: 湖北
社区版块
存档分类
最新评论

c语言冒泡算法

阅读更多

看到网上很多人发布了c语言的冒泡排序,很多不能运行,这里我发布一个不坑爹版

#include <stdio.h>
#include <stdlib.h>
main()
{
	int a[5];
	int i;
	int j;
	int k;
	int temp;
	for(k=0;k<5;k++)
		scanf("%d",&a[k]);//扫描5个数存进数组
	for (i=0;i<5;i++)
		for (j=0;j<5-i-1;j++)
		{
			if (a[j]>a[j+1])//如果前一个大于后面一个,就交换数据
			{
				temp=a[j+1];
				a[j+1]=a[j];
				a[j]=temp;
			}
		}
		for (i=0;i<5;i++)
		{
			printf("%d ",a[i]);//打印数据
		}
		system("pause");
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics