Junior — Middle
Can you explain what Fibonacci sequences are?
sobes.tech AI
Answer from AI
The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, starting from 0 and 1. Formally:
F(0) = 0 F(1) = 1 F(n) = F(n-1) + F(n-2) for n > 1
Example of the first numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21...
In programming, recursive or iterative functions are often used to compute Fibonacci numbers. For example, in C++:
int fibonacci(int n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
The Fibonacci sequence appears in mathematics, nature, and algorithms.