Palindrome Number Triangle in C#

What You’ll Learn
How to build a palindrome triangle in C# by printing an ascending sequence and then mirroring it back down on the same row.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
Output
1
121
12321
1234321
1234543211
Complete C# Program
Print 1..i first, then print i-1..1 to mirror the row.
C#
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int i, j, k;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
Console.Write(j);
for (k = i - 1; k >= 1; k--)
Console.Write(k);
Console.WriteLine();
}
}
}
}🧠 How It Works
1
Outer loop controls rows
i decides how far the sequence grows on each line.
Rows
2
Print ascending part
The first inner loop prints 1..i.
Left half
3
Mirror back down
The second loop prints i-1..1, creating a palindrome.
Right half
=
Palindrome rows
Each row reads the same left-to-right and right-to-left.
2
Variation — User Input Rows
Let the user choose how many rows to print:
C#
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number of rows: ");
int rows = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
Console.Write(j);
for (int k = i - 1; k >= 1; k--)
Console.Write(k);
Console.WriteLine();
}
}
}
}12 people found this page helpful
