#C12216. Nth Fibonacci Number (Recursive)
Nth Fibonacci Number (Recursive)
Nth Fibonacci Number (Recursive)
Given a positive integer n
, compute the nth Fibonacci number using recursion. The Fibonacci sequence is defined as follows:
\(F(1)=0,\quad F(2)=1,\quad F(n)=F(n-1)+F(n-2)\) for \(n > 2\).
If the input n
is not a positive integer, the program should output an error message: n must be a positive integer.
The task is to implement a recursive solution that reads the input from stdin and prints the result to stdout.
inputFormat
The input contains a single line with one integer n
, which represents the position in the Fibonacci sequence.
Note: The input is provided via stdin
.
outputFormat
Output the nth Fibonacci number to stdout
. If n
is not a positive integer, output the error message: n must be a positive integer.
1
0
</p>