You are given an integer limit. Your task is to generate and print all Fibonacci numbers less than than or equal to the given limit, starting from 0 and 1.
Each Fibonacci number after the first two is calculated as the sum of the two preceding numbers. Continue generating terms until the next Fibonacci number exceeds the given limit.
Input: limit = 10
Output: 0 1 1 2 3 5 8
Explanation: These are all the Fibonacci numbers that do not exceed 10.
Input: limit = 1
Output: 0 1 1
Explanation: The Fibonacci numbers up to 1 are 0, 1, and 1.
Input: limit = 0
Output: 0
Explanation: Only the Fibonacci number 0 does not exceed the given limit.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
10
0 1 1 2 3 5 8
1
0 1 1