算法 - C语言
算法的C语言代码
早已忘记
这个作者很懒,什么都没留下…
展开
-
选择法排序
#include <stdio.h>int main(){ int a[5] = {3, 5, 2, 1, 4}; int i, j, tmp, tmp1; int len = (int)(sizeof(a) / sizeof(a[0])); //从小到大排序 for (i = 0; i < len - 1; i++) { tmp = i; for (j = i + 1; j < len; j++) {.原创 2021-04-13 22:02:07 · 99 阅读 · 0 评论 -
冒泡法排序
#include <stdio.h>int main(){ int a[5] = {3, 5, 2, 1, 4}; int i, j, tmp; int len = (int)(sizeof(a) / sizeof(a[0])); //从小到大排序 for (i = 0; i < len - 1; i++) { for (j = 0; j < len - 1 - i; j++) { if (a[j.原创 2021-04-13 22:00:17 · 94 阅读 · 0 评论 -
交换法排序
#include <stdio.h>int main(){ int a[5] = {3, 5, 2, 1, 4}; int i, j, tmp; int len = (int)(sizeof(a) / sizeof(a[0])); //从小到大排序 for (i = 0; i < len - 1; i++) { for (j = i + 1; j < len; j++) { if (a[i] &g.原创 2021-04-13 21:57:26 · 103 阅读 · 0 评论 -
插入法排序
#include <stdio.h>int main(){ int a[5] = { 3, 5, 2, 1, 4 }; int i, j, tmp, pos; int len = (int)(sizeof(a) / sizeof(a[0])); // 从小到大排序 for (i = 1; i < len; i++) { pos = i - 1; tmp = a[i]; while ((pos &.原创 2021-04-13 21:52:49 · 86 阅读 · 0 评论 -
辗转相除法求最大公约数
辗转相除法求最大公约数int main(){ unsigned int num1, num2, tmp; scanf("%u %u", &num1, &num2); if (num1 < num2) { tmp = num1; num1 = num2; num2 = tmp; //确保num1大于等于num2 } while (num2 != 0) { tmp = num1 % num2; //求余数 num1 = num2; num2 =原创 2021-04-09 23:50:55 · 89 阅读 · 0 评论