Example 32: Fibonacci Series

Learn how to print a Fibonacci series.

Problem

Fibonacci series is a series in which each number is the sum of the two preceding ones, starting from 1 and 1.

F0=1F_{0} = 1

F1=1F_{1} = 1

Fn=Fn1+Fn2F_{n}=F_{n-1}+F_{n-2}

Write a program to print the first 10 terms of the Fibonacci series.

Example

Input Output
Nil 1   1   2  3  5  8  13  21  34  55

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Get hands-on with 1400+ tech skills courses.