You are on page 1of 1

#include <iostream>

using namespace std;

int fib(int n)
{
long a=0, b=1;
for (int x = 0; x < n; x++)
{
b += a;
a = b - a;
}
return a;
}
int main()
{
int n;
cout << "Podaj n: ";
cin >> n;
while (n < 1)
{
cout << "n nie moze byc mniejsze od 1! Podaj n: ";
cin >> n;
}
cout << n << ". wyraz ciagu Fibbonacciego = " << fib(n) << endl;
}

You might also like