#include <iostream>
constexprlonglongfibonacci(longlongi){if(i<=2){return1LL;}returnfibonacci(i-1)+fibonacci(i-2);}intmain(){std::cout<<"Fibonacci of 27 is "<<fibonacci(27)<<std::endl;return0;}
Modern C++ can do it more simply, though - this uses constexpr to tell the compiler that it can calculate these at build time if it wants. Using a constexpr arg (here a literal), it probably will do, but we could also pass in a variable to make it calculate it at runtime.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Modern C++ can do it more simply, though - this uses constexpr to tell the compiler that it can calculate these at build time if it wants. Using a constexpr arg (here a literal), it probably will do, but we could also pass in a variable to make it calculate it at runtime.