Created
March 29, 2016 07:06
-
-
Save b4284/55c53ca021e816188d4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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<0> | |
| { | |
| static constexpr int value = 0; | |
| }; | |
| template<> | |
| struct fibonacci<1> | |
| { | |
| static constexpr int value = 1; | |
| }; | |
| int main(void) | |
| { | |
| std::cout << fibonacci<0>::value << std::endl; | |
| std::cout << fibonacci<1>::value << std::endl; | |
| std::cout << fibonacci<2>::value << std::endl; | |
| std::cout << fibonacci<3>::value << std::endl; | |
| std::cout << fibonacci<4>::value << std::endl; | |
| std::cout << fibonacci<5>::value << std::endl; | |
| std::cout << fibonacci<6>::value << std::endl; | |
| std::cout << fibonacci<7>::value << std::endl; | |
| std::cout << fibonacci<8>::value << std::endl; | |
| std::cout << fibonacci<9>::value << std::endl; | |
| std::cout << fibonacci<10>::value << std::endl; | |
| return 0; | |
| } |
whitglint
commented
Mar 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment