鱼C论坛

 找回密码
 立即注册
查看: 1283|回复: 2

c++高精度+递归求斐波拉契第n项怎么写

[复制链接]
发表于 2024-3-24 23:08:37 | 显示全部楼层
  1. #include <iostream>
  2. #include <boost/multiprecision/cpp_int.hpp>

  3. using boost::multiprecision::cpp_int;
  4. using std::cout, std::endl;

  5. cpp_int fibonacci(cpp_int n) {
  6.     if(n == 0) return 0;
  7.     if(n == 1) return 1;
  8.     return fibonacci(n - 1) + fibonacci(n - 2);
  9. }

  10. int main() {
  11.     cout << fibonacci(10) << endl;
  12.     return 0;
  13. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-30 02:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表