
c语言
hertioy
余生很长,当下很短。
展开
-
斐波那契数列
#include<stdio.h>#include<stdlib.h>int fib(int n){if (n<=2)return 1;elsereturn fib(n-1)+fib(n-2);}int main(){{ long n = 0; ret = 0;scanf("%d",&n);ret=fib(n...原创 2019-04-21 11:11:05 · 88 阅读 · 0 评论 -
心型
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int main(){float y, x, a;for (y = 1.5; y > -1.5; y -= 0.1){for (x = -1.5; x < 1.5; x += 0.04){a = xx + ...原创 2019-07-30 12:50:13 · 231 阅读 · 0 评论 -
杨辉三角
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int main(){int a[20][20], n, i, j;printf(“输入n = “);scanf(”%d”, &n);for (i = 0; i < n; ++i){a[i][i] = 1...原创 2019-07-30 13:55:49 · 91 阅读 · 0 评论 -
写一个函数,求两个整数之和,要求在函数体内不得使用四则运算符号
class Solution {public:int Add(int num1, int num2){while(num1!=0){int sum=(num1^num2);int carryBit=(num1&num2)<<1;num2=sum;num1=carryBit;}return num2;}};原创 2019-07-31 10:45:42 · 163 阅读 · 0 评论 -
InserSort
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void InserSort(int* array, int size){for (int i = 1; i < size; ++i){int key = array[i];int end = i - 1;whil...原创 2019-08-08 16:14:04 · 150 阅读 · 0 评论 -
希尔排序(ShellSort)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void ShellSort(int* array, int size){int gap = 3;while (gap > 0){for (int i = gap; i < size; ++i){int k...原创 2019-08-08 17:12:58 · 88 阅读 · 0 评论 -
MergeSort
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <assert.h>#include <string.h>void MergeData(int* array,int left,int...原创 2019-08-13 15:22:37 · 194 阅读 · 0 评论 -
选择排序(SelectSort)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void swap(int* pLeft, int* pRight){int temp = *pLeft;*pLeft = pRight;pRight = temp;}void SelectSort(int array,...原创 2019-08-08 17:55:53 · 132 阅读 · 0 评论 -
选择排序
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void swap(int* pLeft, int* pRight){int temp = *pLeft;*pLeft = pRight;pRight = temp;}void SelectSort(int array,...原创 2019-08-08 18:38:52 · 136 阅读 · 0 评论 -
快排(QuickSort)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void swap(int* left, int* right){int temp = left;left = right;right = temp;}int Partion(int array, int left, ...原创 2019-08-08 20:25:05 · 213 阅读 · 0 评论 -
倒序打印数组
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void Swap(int *x, int *y){int temp = *x;*x = y;y = temp;}void Reverse(int array, int size){if (size <= 1)...原创 2019-08-23 13:40:11 · 399 阅读 · 0 评论 -
递归方式实现打印一个整数的每一位
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>int print(const int n){if (n > 9){print(n / 10);}printf("%d\n", n % 10);}int ma...原创 2019-07-29 13:01:08 · 117 阅读 · 0 评论 -
递归和非递归分别实现求n的阶乘
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>//递归方法/int fac(const int n){if (n == 1 || n == 0)return 1;else{return nfac(n - 1);...原创 2019-07-29 12:54:07 · 126 阅读 · 0 评论 -
二分法找数组中某个元素
#include<stdio.h>int main(){int arr[]={1,2,3,4,5,6,7,8,9,0};int i=0;scanf("%d",&i);int left=0;int right=sizeof(arr)/sizeof(arr[0])-1;mid=left+(right-left)/2;while(left<=righ...原创 2019-04-21 12:11:55 · 157 阅读 · 0 评论 -
Linux基础命令
有关Linux权限的认识,理解权限:就是对某事项进行决策程度和范围,通俗来说,就是规定哪些事情能做、哪些事情不能做。那么,在Linux中有哪些基本权限呢?基本权限:r(读):对于文件而言,具有读文件的权限,对目录而言,具有浏览目录的权限。w(写):对文件而言,具有修改文件的权限,对目录而言,具有删除,移动目录的权限。x(执行):execute对文件而言,具有执行文件的权限,对于目录而言...原创 2019-05-17 13:43:49 · 151 阅读 · 0 评论 -
简要介绍几种了解到的编译器
编译器就是将“一种语言(通常为高级语言)”翻译为“另一种语言(通常为低级语言)”的程序。一个现代编译器的主要工作流程:源代码 (source code) → 预处理器 (preprocessor) → 编译器 (compiler) → 目标代码 (object code) → 链接器 (Linker) → 可执行程序 (executables)。下面介绍一下GCC、Clang、Visual St...原创 2019-05-22 19:17:46 · 980 阅读 · 0 评论 -
在Linux下实现一个进度条程序,通过makefile进行编译
首先,我们需要知道进度条是怎么实现的?进度条的动态效果是利用人眼的视觉暂留做到的。比如说:先输出: “= ”表示1%在下一次则显示:“== ”再一次: “=== ...原创 2019-05-22 19:19:27 · 248 阅读 · 0 评论 -
一个软件的Tarball是如何安装的?
将Tarball由厂商的网页下载下来;将Tarball解开,产生很多的原始码档案;开始以gcc进行原始码的编译(会产生目标文件object files);然后以gcc进行函式库、主、子程序的链接,以形成主要的binary file;将上述的binary file以及相关的配置文件安装至自己的主机上面。RPM安装RPM全名是RedHat Package Manager,简称为RPM,顾名...原创 2019-05-22 19:20:35 · 384 阅读 · 0 评论 -
递归和非递归求斐波那契数
递归实现求第n个斐波那契数#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int fib(int n){if (n <= 2)return 1;elsereturn fib(n - 1) + fib(n - 2);}int main(){int n, ...原创 2019-07-29 10:42:35 · 190 阅读 · 0 评论 -
C语言用递归的方法求n^k
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int Mybow(int n, int k){if (k == 1)return n;elsereturn n*Mybow(n, k - 1);}int main(){int a = Mybow(4, 2);p...原创 2019-07-29 10:56:33 · 201 阅读 · 0 评论 -
C语言用递归函数Digitsum(n),输入一个非负整数,返回组成它的各位数字之和
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int DigitSum(int n){int sum = 0;int m = 0;if (n <= 0)return 0;else{{m = n % 10;n = n / 10;sum = m + Di...原创 2019-07-29 11:09:53 · 326 阅读 · 0 评论 -
编写一个函数 reverse_string(char * string)(递归实现) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数。
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>void reverse_string(char* string){if (*string != ‘\0’){string++;reverse_string(string...原创 2019-07-29 11:29:55 · 127 阅读 · 0 评论 -
递归和非递归分别实现strlen
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>int Mystrlen(const char *string){if (*string){return 1 + Mystrlen(string + 1);}else...原创 2019-07-29 11:39:32 · 83 阅读 · 0 评论 -
BubbleSort
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void BubbleSort(int* array, int size){for (int i = 0; i < size - 1; i++){for (int j = i + 1; j < size; j++...原创 2019-08-28 22:22:00 · 200 阅读 · 0 评论