logoStarPatterns
Back to Patterns

Fibonacci Triangle

Pattern Result

1
1 1
1 1 2
1 1 2 3
1 1 2 3 5

Code Implementation

Explanation

The Fibonacci Triangle pattern creates a triangle filled with Fibonacci numbers. Each row contains one more number than the previous row, and each number is part of the Fibonacci sequence (where each number is the sum of the two preceding ones, starting from 0 and 1). The outer loop iterates from 1 to n, representing each row. For each row, we reset the Fibonacci sequence and generate the first i Fibonacci numbers using the inner loop. This creates a triangle where each position contains the next Fibonacci number in the sequence.