Cod sursa(job #2155776)

Utilizator ohnoohnoSpalatelu Silvia ohnoohno Data 8 martie 2018 09:14:53
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("kfib.in");
ofstream g("kfib.out");
long long k,a,b,c,i;
/*int fib(int n)
{
    if (n==1 || n==2) return 1;
    else return(fib(n-1)+fib(n-2));
}*/
int main()
{
    f>>k;
    if (k==1 || k==2) g<<1;
    else
    {
        a=1;
        b=1;
        for (i=3;i<=k;i++)
        {
            c=a+b;
            a=b;
            b=c;
        }
        g<<c;

    }

    return 0;

}