冒泡排序
# include <stdio.h> int main() { int a[6] = { 900, 2, 3, -58, 34, 76 }; int i; //比较的轮数 int j; //每轮比较的次数 int buf; //交换数据时用于存放中间数据 for (i = 0; i < 6; ++i) { for (j = 0; j < 5 - i; ++j) { if (a[j] < a[j + 1]) { buf = a[j]; a[j] = a[j + 1]; a[j + 1] = buf; } } } for (i = 0; i < 6; ++i) { printf("%d\x20", a[i]); } printf("\n"); while (1); return 0;