![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C语言算法
风起的年华
这个作者很懒,什么都没留下…
展开
-
堆排序-大根堆
#include<stdio.h>#include<stdlib.h>// 大根堆-堆排序void get_heap_max(int *arr, int length) { //每执行一次最大值都在放置在数组首位 int child, parent; for (int i = length - 1; i > 0; i--) { child = i, p...原创 2020-02-28 11:02:39 · 3372 阅读 · 0 评论 -
快排算法
#include<stdio.h>#include<stdlib.h>/*#include <stdio.h>int qusort(int s[], int start, int end) //自定义函数 qusort(){ int i, j; //定义变量为基本整型 i = start; //将每组首个元素赋给i j = en...原创 2020-02-28 10:56:58 · 115 阅读 · 0 评论 -
数组删除重复元素
#include<stdio.h>#include<stdlib.h>#define N 24int a[N] = { 1,5,3,2,5,4,6,5,7,9,6,2,66,4,1,55,5,7,5,9,5,7,5,9 };int main() { int cnt = N; printf("数组a的元素依次为:\n"); for (int i = 0; i...原创 2020-02-27 15:33:31 · 311 阅读 · 0 评论 -
求元素出现个数
#include<stdio.h>#include<stdlib.h>int a[24] = { 1,5,3,2,5,4,6,5,7,9,6,2,66,4,1,55,5,7,5,9,5,7,5,9 };//数组b用于记录元素出现的次数int b[24] = { 0 };int main() { printf("数组a的元素依次为:\n"); for (in...原创 2020-02-27 15:32:20 · 240 阅读 · 0 评论 -
求数组元素中出现次数最多_最少的元素
#include<stdio.h>#include<stdlib.h>//寻找数组中最大元素int get_max(int count[]) { int max = count[0]; for (int i = 1; i < 12; i++) { if (count[i] > max) { max = count[i]; } } re...原创 2020-02-27 15:29:58 · 1405 阅读 · 0 评论 -
交集_并集
#include<stdio.h>#include<stdlib.h>void main() { int a[20] = { 12,8,5,4,11,2,13,14,15,16,17,18,19,20,21,22,23,24,25,26 }; int b[15] = { 88,99,77,55,44,17,18,19,20,21,22,23,24,25,26 };...原创 2020-02-27 15:27:02 · 326 阅读 · 1 评论 -
累加的递归形式
#include<stdio.h>#include<stdlib.h>//累加的递归形式int add(int num) { if (num == 1) return 1; else{ return num + add(num - 1); }}int main() { int number; printf("请输入累加的最后一个数字:\n");...原创 2020-02-27 15:25:01 · 608 阅读 · 0 评论 -
递归判断数组元素递增
#include<stdio.h>#include<stdlib.h>//递归判断判断数组元素是否递增int isit(int arr[], int length) { if (length == 1) { return 1; } else if(length == 2){ return arr[1] > arr[0]; } else { ...原创 2020-02-27 15:23:34 · 208 阅读 · 0 评论 -
二分查找
#include<stdio.h>#include<stdlib.h>/*int low = 0, high = 9, num, count = 0, cnt = 0, mid;scanf_s("%d", &num);while (low <= high) { cnt++; mid = (low + high) / 2; if (a[mid]...原创 2020-02-27 15:22:23 · 73 阅读 · 0 评论 -
插入排序
#include<stdio.h>#include<stdlib.h>int main() { int a[10] = {10,9,8,7,6,5,4,3,2,1}; for (int i = 0; i < 10; i++) { printf("%3d", a[i]); } for (int i = 1; i < 10; i++) { int...原创 2020-02-27 15:21:07 · 79 阅读 · 0 评论 -
选择排序
#include<stdio.h>#include<stdlib.h>int main() { int max,min,temp, a[10] = {0}; for (int i = 0; i < 10; i++) { a[i] = (10-i) * (10-i) + 1; printf("%d\t", a[i]); } //选择排序,注意i...原创 2020-02-27 15:19:46 · 53 阅读 · 0 评论 -
冒泡排序
#include<stdio.h>#include<stdlib.h>int main() { //一次冒泡过程模拟 int a[10] = {8,5,9,6,453,7,73,2,11,32}; for (int i = 0; i < 10-1; i++) { if (a[i] > a[i + 1]) { int temp = a[i];...原创 2020-02-27 15:18:31 · 66 阅读 · 0 评论 -
最小公倍数_最大公约数
#include<stdio.h>#include<stdlib.h>int fun(int m, int n) { if (m%n == 0) return n; else return fun(n, m%n);}int main() { int a = 25, b = 10; printf("%d\t%d\t最小公倍数:%d\t最大公约数:%d\n",...原创 2020-02-27 15:17:08 · 74 阅读 · 0 评论 -
进制转换
#include<stdio.h>#include<stdlib.h>void to2(int num) { if (num == 0) return; else { to2(num / 2); printf("%d", num % 2); }}void to8(int num) { if (num == 0) return; else { ...原创 2020-02-27 15:16:01 · 65 阅读 · 0 评论 -
质数列举
#include<stdio.h>#include<stdlib.h>void main() { for (int i = 2; i < 100; i++) { int a = 0; for (int j = 1; j < i; j++) { if (i % j == 0 ) { a++; } } if (a == 1...原创 2020-02-27 15:14:36 · 385 阅读 · 0 评论 -
9*9乘法表
#include<stdio.h>#include<stdlib.h>#include<Windows.h>void main() { for (int i = 1; i < 10; i++) { for (int j = 1; j < i + 1; j++) { printf("%d * %d = %d\t",j,i, i*j)...原创 2020-02-27 15:11:43 · 115 阅读 · 0 评论 -
台阶问题
#include<stdio.h>int taijie(int a1) { if (a1 == 0) return -1; if (a1 == 1) return 0; if (a1 == 1) return 1; int a = 1, b = 1, s = 0; for (int i = 2; i < a1 + 1; i++) { s = a + b; ...原创 2020-02-27 15:09:52 · 205 阅读 · 0 评论 -
水仙花数
#include<stdio.h>#include<stdlib.h>int main() { int a, b, c; for (int i = 100; i < 999; i++) { a = i / 100; b = i / 10 % 10; c = i % 10; if (a * a * a + b * b * b + c * c *...原创 2020-02-27 15:08:29 · 85 阅读 · 0 评论 -
斐波那切数列递归算法
#include<stdio.h>#include<stdlib.h>int fibo(int a) { if (a == 0 || a == 1) return 1; else { return fibo(a - 1) + fibo(a - 2); }}int main() { int a; printf("请输入一个整数:\n"); sca...原创 2020-02-27 15:07:07 · 299 阅读 · 0 评论 -
整数逆制
#include<stdio.h>int main() { int num; int res = 0, num1 = 0; scanf_s("%d", &num); while (num != 0) { num1 = num % 10; res = num1 + 10 * res; num = num / 10; } printf("逆制后的数字为...原创 2020-02-27 15:03:33 · 184 阅读 · 0 评论 -
汉诺塔过程模拟
汉诺塔过程模拟#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>int a10 = {0};void show(int a10); //策略显示void move(char X, char Y);//移动过程void hanno(int n, char A, char B, ...原创 2020-01-30 22:04:16 · 513 阅读 · 0 评论