blob: 449d7d63a965a7fb4bcfdc0b0983dab934b4436b [file] [log] [blame]
#include <iostream>
using namespace std;
//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template <class T>
T fib(unsigned int n, const T& fib0) {
T a(fib0), b(fib0);
for (; n; --n) {
T tmp(a);
a += b;
b = tmp;
}
return a;
}
int main(int argc, char **argv) {
cout << fib(10, 1U);
}