Created
June 11, 2015 22:20
-
-
Save macmade/1e0ae368725f768e5a21 to your computer and use it in GitHub Desktop.
C++ Fibonacci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template< int N > | |
struct Fibonacci | |
{ | |
static constexpr int value = Fibonacci< N - 1 >::value + Fibonacci< N - 2 >::value; | |
}; | |
template<> | |
struct Fibonacci< 1 > | |
{ | |
static constexpr int value = 1; | |
}; | |
template<> | |
struct Fibonacci< 0 > | |
{ | |
static constexpr int value = 0; | |
}; | |
int main( void ) | |
{ | |
std::cout << Fibonacci< 40 >::value << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment