Home Algorithmic problems Fibonacci EASY Fibonacci numbers are a sequence of numbers in which the first two numbers are 0 and 1, and each subsequent number is equal to the sum of the two previous numbers. You should to write code that prints the first n numbers of this sequence. INPUT: n - count of numbers to print OUTPUT: a sequence of numbers separated by spaces Example #1 Input 6 Output 0 1 1 2 3 5 Example #2 Input 4 Output 0 1 1 2 Solution Our solution × <?php $n = (int)trim(fgets(STDIN)); if ($n === 0) { return; } if ($n === 1) { echo 0; return; } $fib = [0, 1]; for($i=1; $i < $n-1; $i++) { $fib[] = $fib[$i] + $fib[$i-1]; } echo implode(' ', $fib); Select programming language C (GCC 9.3.0) Java (OpenJDK 1.8) Python (3.8) C++ (GCC 9.3.0) C# (Mono 6.8) JavaScript (NODE 14.1) PHP (7.4) Go (1.14) Kotlin (JVM 1.3.72) Swift (5.2) Run Show our solution Tests Test #1 Loading... Test #2 Loading... Test #3 Loading... Test #4 Loading... Test #5 Loading... Test #6 Loading... Test #7 Loading... Result