斐波那契数
来源:互联网 发布:nginx访问日志格式 编辑:程序博客网 时间:2024/05/17 22:03
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>//递归法求斐波那契数(图1)long fibonacci(int n){if (n <= 2)return 1;return fibonacci(n - 1) + fibonacci(n - 2);}//迭代法求斐波那契数(图2)long fibonacci(int n){long Pre;long Cur;long Result;Pre = 1;Cur = 1;for (int i = 3; i <= n; i++){Result = Pre + Cur;Pre = Cur;Cur = Result;}return Result;}//迭代法求斐波那契数(图3)long fibonacci(int n){long result;long previous_result;long next_older_result;result = previous_result = 1;while (n > 2){n--;next_older_result = previous_result;previous_result = result;result = previous_result + next_older_result;}return result;}
阅读全文
0 0
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- 斐波那契数
- OpenCV-将图像缩放并显示
- CircleImageView 圆形imageView(转载)
- 第四周项目5(2)--- 循环双链表应用
- mongodb sparse &unique
- MySQL添加函数或存储过程,步骤
- 斐波那契数
- Linux硬件信息命令大全
- java基础整理
- CodeForces
- SPI详解
- c++20170929
- 网络编程复习(八):Netty解决拆包粘包问题--定长方式
- 多重运算的Mac计算器
- Fast R-CNN