用c++写一个冒泡排序的代码
时间: 2023-04-08 09:04:42 浏览: 83
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
printf("输入数组大小\n");
scanf("%d", &n);
printf("输入 %d 数字\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < n - 1; c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1])
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf("排序后的结果:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
阅读全文