1 solutions

  • 0
    @ 2024-12-10 23:49:12

    C++ :

    #include <iostream>
    #include <cmath>
    using namespace std;
    int n;
    int f(int x)
    {
      if (x==0) return 0;
      if (x==1) return 1;
      if (x>1) return f(x-1)+f(x-2);
    }
    int main()
    {
      cin>>n;
      cout<<f(n)<<endl;
     // system ("pause");
      return 0;
    }
    
    

    Pascal :

    program dg;
    var
     n:longint;
    function dg(n:longint):longint;
    
    begin
     if n=0 then dg:=0
     else if n=1 then dg:=1
     else dg:=dg(n-1)+dg(n-2);
    end;
    begin
     readln(n);
     writeln(dg(n))
    end.
    
    
    • 1

    Information

    ID
    634
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    9
    Accepted
    0
    Uploaded By