Returns the nth term of the Fibonacci sequence.

Use recursion to calculate the nth term in the Fibonacci sequence.

代码实现

int fibonacci(int n) {
  if (n <= 0) return 0;
  return n < 2 ? n : (fibonacci(n - 1) + fibonacci(n - 2));
}

使用样例

fibonacci(6); // 8