VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-print-fibonacci-triangle/

⇱ Program to print Fibonacci Triangle - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print Fibonacci Triangle

Last Updated : 10 Aug, 2022

Given the value of n(n < 10), i.e, number of lines, print the Fibonacci triangle.

Examples: 

Input : n = 5 
Output :
1 
1 2 
3 5 8 
13 21 34 55 
89 144 233 377 610 

Input : n = 7
Output :
1 
1 2 
3 5 8 
13 21 34 55 
89 144 233 377 610 
987 1597 2584 4181 6765 10946 
17711 28657 46368 75025 121393 196418 317811 

The Fibonacci numbers are the numbers in the following integer sequence.
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ........
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation 

 Fn = Fn-1 + Fn-2

with seed values F1 = 1 and F2 = 1.

Below is the implementation of the above pattern :  

Output: 

1 
1 2 
3 5 8 
13 21 34 55 
89 144 233 377 610 


Time complexity: O(n*n)

Auxiliary Space: O(n)

Comment
Article Tags: