Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- constexpr unsigned long long fib(unsigned short num)
- {
- return ((num == 0) ? 1 : (
- (num == 1) ? 1 : (
- fib(num - 2) + fib(num - 1))));
- }
- int main()
- {
- using ::std::cout;
- constexpr unsigned short val = 46;
- // Since result is constexpr, it MUST be computed at compile-time.
- constexpr unsigned long long result = fib(val);
- cout << "fib(" << val << ") == " << fib(val) << '\n';
- cout << "fib(" << val << ") == " << result << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement