#C12956. Fibonacci Sequence Generation
Fibonacci Sequence Generation
Fibonacci Sequence Generation
Given an integer n, generate the Fibonacci sequence using an iterative approach such that every term in the sequence is less than or equal to n. The Fibonacci sequence is defined as follows:
\(F_0 = 0,\ F_1 = 1,\) and \(F_{k} = F_{k-1} + F_{k-2}\) for \(k \ge 2\). Note that for this problem, when n is 1, the sequence should include all Fibonacci numbers \(\le 1\) (which results in a repeated 1).
If the input integer is negative, output nothing (an empty line).
Your task is to implement a function that reads the input from standard input and prints the Fibonacci sequence (numbers separated by a space) to standard output.
inputFormat
The input consists of a single integer n provided via standard input.
Example Input:
5
outputFormat
Output a single line containing the Fibonacci sequence (all numbers less than or equal to n), separated by a single space.
Example Output for input 5:
0 1 1 2 3 5
0
0