C语言·冒泡排序
前言说明实现思路流程图冒泡排序·代码·有注释冒泡排序·代码结语 前言说明
将一串自己输入的数字,通过冒泡排序,由小到大进行输出。
实现思路
将第一个数与第二个数比较;满足条件就换位;将第二个数与第三个数比较;满足条件就换位;将第三个数与。。。。。。(以此类推)
流程图
暂无
冒泡排序·代码·有注释
#include #define value_1 5int main(int argc, char* argv[]){int clas_1[value_1];int value_2 = 0;int value_3 = 0;int i;printf("请输入%d个数:", value_1);for (i = 0; i < value_1; i++){scanf_s("%d", &clas_1[i]);}printf("nn您输入的数是:");for (i = 0; i < value_1; i++){printf("%d", clas_1[i]);if (i < value_1 - 1){printf(",");}}i = 0;for (value_2 = 0; value_2 < (value_1 - 1); value_2++){for (value_3 = 0; value_3 < ((value_1 - 1) - value_2); value_3++){if (clas_1[value_3] > clas_1[value_3 + 1]){i = clas_1[value_3];clas_1[value_3] = clas_1[value_3 + 1];clas_1[value_3 + 1] = i;}}}printf("nn排序后的结果是:");for (i = 0; i < value_1; i++){printf("%d", clas_1[i]);if (i < value_1 - 1){printf("<");}}printf("n");return 0;}
冒泡排序·代码
#include #define value_1 5int main(int argc, char* argv[]){int clas_1[value_1];int value_2 = 0;int value_3 = 0;int i;printf("请输入%d个数:", value_1);for (i = 0; i < value_1; i++){scanf_s("%d", &clas_1[i]);}printf("nn您输入的数是:");for (i = 0; i < value_1; i++){printf("%d", clas_1[i]);if (i < value_1 - 1){printf(",");}}i = 0;for (value_2 = 0; value_2 < (value_1 - 1); value_2++){for (value_3 = 0; value_3 < ((value_1 - 1) - value_2); value_3++){if (clas_1[value_3] > clas_1[value_3 + 1]){i = clas_1[value_3];clas_1[value_3] = clas_1[value_3 + 1];clas_1[value_3 + 1] = i;}}}printf("nn排序后的结果是:");for (i = 0; i < value_1; i++){printf("%d", clas_1[i]);if (i < value_1 - 1){printf("<");}}printf("n");return 0;}
结语
编程新手。此代码有错误的或者有意见的,欢迎致信!
QQ邮箱:2787485199@qq.com