Challenge 12

♾️

Fibonacci Sequence

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

Write a procedure to print the first n numbers in the Fibonacci sequence

The first 2 numbers are 0 and 1, then the remaining numbers are the sum of the previous two - i.e:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 etc

Examples:

fibonacci(5) would output 0,1,1,2,3

Extension:

Adapt the procedure to take in a start and end position - for example, a start position of 5 and end position of 10 would output the sequence 5, 8, 13, 21, 34

Write the sequence to a file with an appropriate name, based on the parameters passed into the procedure. Each number should be on a new line in the file

Solutions

IGCSE 0478 / O-Level 2210 A-Level 9618