Practice

First N Fibonacci Numbers

HARDAlgorithms

Read a positive integer N. Output the first N Fibonacci numbers, one per line.

The sequence starts: 0, 1, 1, 2, 3, 5, 8, 13, 21, …

Input: A positive integer N (1 ≤ N ≤ 15). Output: The first N Fibonacci numbers, one per line.

Example (N = 5):

0
1
1
2
3

Sample Test Cases

Test 1: First 5
Inputs: 5
Expected: 0 1 1 2 3
Test 2: First 8
Inputs: 8
Expected: 0 1 1 2 3 5 8 13
Test 3: N = 1
Inputs: 1
Expected: 0

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started