#include int main(int argc, const char *argv[]){int a[10] = {0};int len = sizeof(a) / sizeof(a[0]);int i = 0;int j = 0;int temp = 0;srand(time(NULL));for (i = 0;i < len;i++){a[i] = rand() % 100; //产生随机数}for (j = 0;j < len-1;j++){for (i = 0;i < len-1-j;i++){if (a[i] > a[i+1]){temp = a[i];a[i] = a[i+1];a[i+1] = temp;//完成两个数的交换有三种方法,可以搜索一下。。}}}for (i = 0;i < len;i++){printf("%d ", a[i]);}printf("\n");return 0;}
C语言中冒泡排序的图解
最新推荐文章于 2024-07-15 12:54:34 发布