一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>//实现buble_sort函数;
void buble_sort(int arr[], int sz)
{//初始化变量值;int i = 0;//嵌套循环冒泡排序;//外层循环;for (i = 0; i < sz; i++){//一趟冒泡排序过程;//初始化变量值;int j = 0;//内层循环;for (j = 0; j < sz - 1 - i; j++){//判断前后大小;if (arr[j] > arr[j + 1]){//交换;int tmp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = tmp;}}}
}int main()
{//初始化数组值;int arr[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };int i = 0;//求出数组的长度;int sz = sizeof(arr) / sizeof(arr[0]);//定义冒泡排序函数;buble_sort(arr, sz);//用for循环打印结果;for (i = 0; i < sz; i++){//打印结果;printf("%d ", arr[i]);}return 0;
}