注册 登录
编程论坛 VC++/MFC

用递归方法编程计算斐波那契数列

临州烟雨 发布于 2014-10-25 17:58, 567 次点击
如何用递归方法编程计算斐波那契数列
2 回复
#2
yuccn2014-10-28 12:08
http://blog.
#3
米兰达斯2014-11-01 11:23
程序代码:
#include <stdio.h>
void main()
{
    int fx(int n); //声明函数
    int n,i;
    printf("请输入要求第几项:");
    scanf("%d",&n);
    i=fx(n);
    printf("第%d项为%d。\n",n,i);
}
int fx(int n)
{
    int t;
    if(n==2||n==1) t=1; //第一项和第二项为1
    else t=fx(n-1)+fx(n-2); //第n项为前两项之和
    return t;
}
1