RosettaCodeData/Task/Anonymous-recursion/C++/anonymous-recursion-3.cpp
Ingy döt Net 6f050a029e update
2013-06-05 21:47:54 +00:00

26 lines
355 B
C++

double fib(double n)
{
if(n < 0)
{
throw "Invalid argument passed to fib";
}
else
{
struct actual_fib
{
double operator()(double n)
{
if(n < 2)
{
return n;
}
else
{
return (*this)(n-1) + (*this)(n-2);
}
}
};
return actual_fib()(n);
}
}