#C12187. Fibonacci Numbers: Recursive and Iterative Methods
Fibonacci Numbers: Recursive and Iterative Methods
Fibonacci Numbers: Recursive and Iterative Methods
Given an integer n, compute the n-th Fibonacci number. The Fibonacci sequence is defined as follows:
$$F(0)=0, \quad F(1)=1, \quad F(n)=F(n-1)+F(n-2), \quad \text{for } n\geq 2.$$
This problem invites you to explore both recursive and iterative methods for computing Fibonacci numbers. Although the recursive approach demonstrates the concept of recursion, the iterative method is more efficient for larger values of n. Read the integer n from standard input and output the n-th Fibonacci number to standard output.
inputFormat
The input consists of a single integer n (0 ≤ n ≤ 40) provided via standard input.
outputFormat
Output a single integer, which is the n-th Fibonacci number, to standard output.
## sample0
0