Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename fib> //szablon na liczbe is slowa Fibonacciego oraz liczbe Lucasa
- fib FibNum(int m, fib a, fib b) {
- if (m==0){return a;}
- if (m==1){return b;}
- return FibNum(m-1, a, b) + FibNum(m-2, a, b); //rekurencyjne wyliczenie wartosci dla dowolnej liczby w ciagu, dziala niezaleznie od zmiennych
- }
- int main() {
- cout<<FibNum(5,0,1)<<endl;
- cout<<FibNum(5,2,1)<<endl;
- cout<<FibNum(5,string("b"),string("a"))<<endl; //nalezy wymusic interpretowanie "a" oraz "b" jako stringow, a nie charow, poniewaz stringi mozna dodawac
- cout<<FibNum(5,string("0"),string("01"))<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement