CJCoding With Joseph
15free / daySign inCreate account

Function: Nth Fibonacci

Complete the function fib so it returns the nth Fibonacci number (1-indexed, where fib(1)=0, fib(2)=1, and each later term is the sum of the previous two). The main function reads n and prints fib(n).

Example: input 7 prints 8 (sequence: 0 1 1 2 3 5 8).

Expected Output:

8

= newline. No newline after the last line.

Hints4 available
Topics:
Functions/Methods
📥 Auto-Input:
7\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.