当前位置:网站首页>用递归法求Fibonacci数列第n项的值
用递归法求Fibonacci数列第n项的值
2022-06-22 15:03:00 【小木荣】
用递归法求Fibonacci数列第n项的值。该数列有如下的特点:第1个数和第2个数都为1,从第3个数开台,每个数都是其前面两个数之和。
#include <stdio.h>
unsigned Fib(unsigned n)
{
if(n>2)
return Fib(n-1)+Fib(n-2);
else
return 1;
}
int main(void)
{
unsigned n,ret;
puts("请输入Fibonacci第n项:");
scanf("%d",&n);
ret=Fib(n);
printf("Fib第%d项为:%d\n",n,ret);
return 0;
}
边栏推荐
猜你喜欢
![[译文] 弥合开源数据库和数据库业务之间的鸿沟](/img/e5/f89a8f3e2e9034f557ea3e76f37f81.jpg)
[译文] 弥合开源数据库和数据库业务之间的鸿沟

Runtime -- explore the nature of classes, objects, and classifications
New design of databend SQL planner

Unity游戏优化(第2版)学习记录8

SLAM十四讲之第6讲--非线性优化

SAP ABAP 中的用户出口和客户出口-015

Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance

什么是 SAP ABAP? 类型、ABAP 完整形式和含义

数睿数据受邀参与南通企业数字化转型研讨会

SAP 脚本教程:SE71、SE78、SCC1、VF03、SO10-013
随机推荐
SAP ABAP BAPI-016
SAP ABAP 中 OpenSQL和Native SQL-05 本教程的目的不是教您 SQL 或数据库概念
Rosbag使用命令
How to embody the value of knowledge management in business
Default function control =default and =delete
华为云HCDEZ专场暨分布式技术峰会:华为云分布式云原生技术与实践之路
C language learning -17- function is passed in as a parameter
Unity game optimization (version 2) learning record 8
Batch export excel zip using zipfile, openpyxl and flask
预约打新债到底安不安全呀?是不是靠谱的?
3.抽象类(shape)
GD32F4xx MCU 驱动mcp2515扩展CAN接口
MySQL trigger
SAP ABAP 表控制与示例-07
SAP ABAP 中的用户出口和客户出口-015
数睿数据深度 | 关于软件自主可控,源代码向左,无代码向右
webDriver以及Selenium使用总结
The odoo system sets priorities for the views independently developed by the original model
Google Chrome small details
【山大会议】注册页的编写