Back to Patterns
Palindrome Triangular
Pattern Result
12 1 23 2 1 2 34 3 2 1 2 3 45 4 3 2 1 2 3 4 5
Code Implementation
Explanation
The Palindrome Triangular pattern creates a triangle where each row forms a palindrome sequence of numbers. Each row starts with the row number, decreases to 1, and then increases back to the row number. For example, row 3 contains the sequence 3, 2, 1, 2, 3. The outer loop iterates from 1 to n, representing each row. For each row, we use two inner loops: the first loop adds numbers in decreasing order from the row number down to 1, and the second loop adds numbers in increasing order from 2 up to the row number.