Descending Repeating Number Triangle in C#

What You’ll Learn
How to print a descending repeating number triangle in C#. Each line prints the same digit multiple times: it starts with rows (printed once), then repeats rows-1 twice, rows-2 three times, and continues until 1.
This pattern is a great way to practice nested-loop boundaries and see how the inner-loop run count changes per row.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
5
44
333
2222
11111Complete C# Program
The outer loop decreases the digit. The inner loop repeats it the required number of times for that row.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int rows = 5;
int i, j;
for (i = rows; i >= 1; i--)
{
for (j = rows; j >= i; j--)
{
Console.Write(i);
}
Console.WriteLine();
}
}
}
}🧠 How It Works
Set the size
int rows = 5; decides the starting digit and the triangle height.
Outer loop (choose the digit)
for (i = rows; i >= 1; i--) picks the digit to print on each row (5, then 4, then 3, … down to 1).
Inner loop (repeat count grows)
for (j = rows; j >= i; j--) repeats i more times as i decreases. That’s why 4 prints twice, 3 prints three times, etc.
New line
Console.WriteLine() ends each row so the next row starts on a new line.
Repeating number triangle
Total prints are 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.
Variation — User Input Version
Read the row count using Console.ReadLine() so the pattern can scale:
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 = rows; i >= 1; i--)
{
for (int j = rows; j >= i; j--)
{
Console.Write(i);
}
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Validate input with
int.TryParsebefore converting - Add spaces between digits with
Console.Write(i + " ") - Flip it to an ascending repeating pattern by counting
iupward and adjusting the inner-loop bounds - Print the row index instead of the digit for different visuals
Avoid
- Forgetting
Console.WriteLine()after each row - Using
Convert.ToInt32without handling invalid input - Mixing the inner-loop bounds (it controls the repeat count)
Key Takeaways
The digit decreases from rows down to 1, but the repeat count increases.
The inner loop controls how many times the digit prints on each line.
Total prints follow triangular numbers: n(n+1)/2.
Reading rows from the console makes your pattern program reusable.
❓ Frequently Asked Questions
rows down to i. When i becomes 1, the inner loop runs rows times, so 1 is repeated the most.rows to any positive integer. The first row prints that number once and the last row prints 1 repeated rows times.n rows because the total number of prints is n(n+1)/2.Explore More C# Number Patterns!
Practice loop logic with pyramids, alternating rows, and more number-based designs.
If you print n rows, the total number of digits printed is n(n+1)/2. That’s why these triangle patterns are often used to introduce triangular numbers.
12 people found this page helpful
