![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
递归
菠萝菠萝菠萝葡萄
这个作者很懒,什么都没留下…
展开
-
自实现atol
分析:1.如果从前到后把字符串遍历,那么怎么知道第一个数需要乘多少?答:不需要知道,只要每向后走一步,前面的数字就乘10#include <stdio.h>//自实现,atollong atol(const char* strNumber){ long number = 0; int a = 0; while (*strNumber != 0) { number = number * 10 + *strNumber - '0';原创 2021-03-01 20:11:43 · 114 阅读 · 0 评论 -
求n!递归和非递归
#include <stdio.h>//求n!int jiecheng(int n){ int res=1; while (n>1) { res*=n--; }}int jiecheng2(int n){ if(n>1) { return jiecheng2(n-1)*n; } else if(n==1) { return 1; }}原创 2021-03-13 14:31:30 · 294 阅读 · 0 评论 -
斐波那契数列
#include <stdio.h>//1,1,2,3,5,8,13这个数列叫斐波那契数列,//编程实现第N个数的值int feibonaqie(int n){ if(n==1||n==2) { return 1; } else { return feibonaqie(n-2)+feibonaqie(n-1); }}int main(int argc, char *argv[]){ pri原创 2021-03-12 19:14:02 · 118 阅读 · 0 评论 -
求递归的结果
#include <iostream>#include<stdio.h>using namespace std;int f(int n){ if(n) return f(n-1)+n; else return n;}int main(int argc, char *argv[]){ int a = f(4); printf("%d\n",a); cout << f(4) <&l原创 2021-03-03 08:21:03 · 150 阅读 · 0 评论 -
兔子问题
一只兔子出生第4年开始生小兔,问n年后兔子有多少#include <iostream>using namespace std;int rabit_num(int year){ return year<4?1:rabit_num(year-4)+rabit_num(year-1);}int main(int argc, char *argv[]){ int n = rabit_num(7); cout<<n<<endl;原创 2021-03-02 20:49:59 · 160 阅读 · 0 评论