首页 > 试题广场 >

Fibonacci

[编程题]Fibonacci
  • 热度指数:16784 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} are defined by the recurrence:     F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2     Write a program to calculate the Fibonacci Numbers.

输入描述:
    Each case contains a number n and you are expected to calculate Fn.(0<=n<=30) 。


输出描述:
   For each case, print a number Fn on a separate line,which means the nth Fibonacci Number.
示例1

输入

1

输出

1
头像 ading520
发表于 2022-03-11 16:38:50
#include<iostream> #include<cstdio> using namespace std; const int MAXN = 10; struct Matrix { int row; int col; int matrix[MAXN][MAX 展开全文
头像 ading520
发表于 2022-03-02 17:41:16
">#include<iostream> using namespace std; int Fibonacci(int n){ if(n == 1 || n == 0){ return n; } return Fibonacci(n -1) + Fibonacci(n - 展开全文
头像 牛客910759732号
发表于 2026-03-19 09:47:01
#include <stdio.h> using namespace std; int fibonacci(int n ){ if(n==0){ return 0; }else if(n==1){ return 1; }else{ 展开全文
头像 TomatoHead
发表于 2024-03-09 16:19:18
#include <iostream> #include <cstdio> #include <vector> #include <string> using namespace std; int Fun(int n) { if (n > 展开全文
头像 哆啦A梦的百宝袋1234
发表于 2024-01-16 23:57:55
#include <iostream> using namespace std; int fun(int n){ if(n==0) return 0; else if(n==1) return 1; else return fun(n-1)+fun(n-2); } 展开全文
头像 秋起木槿
发表于 2023-03-09 20:17:32
#include "cstdio" #include <cstdio> using namespace std; int main(){ int n; scanf("%d",&n); int a=0,b=1; for(int i=2;i<=n;i 展开全文
头像 吴明示
发表于 2022-02-27 20:30:52
注释掉的是递归做法 #include <cstdio> #include <iostream> using namespace std; //同样地,递归和循环都写一下 // int digui(int n){ // if(!n){ // return 0; // 展开全文
头像 whoway
发表于 2020-12-07 10:17:13
#include<bits/stdc++.h> using namespace std; long long n; long long solve[31]; void init() { solve[0]=0; solve[1]=1; for(int i=2; i 展开全文
头像 爱吃的懒羊羊离上岸不远了
发表于 2025-03-03 14:55:31
#include <iostream> #include <algorithm> #include <cmath> using namespace std; int F[35]; int Fib(int x) { if(x==0) { 展开全文
头像 在春招的王者很想去西藏旅游
发表于 2024-03-12 17:18:20
#include <bits/stdc++.h> using namespace std; int Fibo(int n){ if(n==0) return 0; else if(n==1) return 1; return Fibo(n-1)+Fibo(n-2) 展开全文