Reverse Ascending Number Triangle in C#

What You’ll Learn
How to print a reverse ascending number triangle in C#. The first row prints just the highest digit, then each next row adds one more digit to the left: 5, 45, 345, 2345, 12345.
This pattern is a great exercise for learning how changing the inner loop start value changes the overall shape.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
5
45
345
2345
12345Complete C# Program
The outer loop counts down from rows to 1. The inner loop prints from i up to rows.
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 = i; j <= rows; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
}🧠 How It Works
Pick the height
int rows = 5; sets both the maximum digit and the number of rows.
Outer loop (descending start)
for (i = rows; i >= 1; i--) moves the starting value leftward from 5 down to 1.
Inner loop (print i..rows)
for (j = i; j <= rows; j++) prints from the current start to the maximum digit.
New line
Console.WriteLine() moves to the next row.
Reverse ascending triangle
Total printed digits are still triangular: 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.
Variation — User Input Version
Read the row count at runtime:
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 = i; j <= rows; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Validate input with
int.TryParsebefore converting - Add spaces with
Console.Write(j + " ")for readability - Flip it to a left-shifted version by starting the inner loop at
iand ending atrows(Program 2) - Right-align the rows by printing leading spaces before the numbers
Avoid
- Forgetting
Console.WriteLine()after each row - Using
Convert.ToInt32without handling invalid input - Mixing up loop bounds (the inner loop must start at
i)
Key Takeaways
The outer loop moves the starting value from rows down to 1.
The inner loop prints from i to rows, growing each row.
Total digits printed are triangular: n(n+1)/2.
Adjusting only the loop start values can dramatically change the output shape.
❓ Frequently Asked Questions
i decreases from 5 to 1, so the inner loop prints more digits each next row.1..i on each row. This program prints i..rows, so the first row starts with the maximum digit and grows by adding digits to the left.n(n+1)/2.Explore More C# Number Patterns!
Keep practicing loop bounds with inversions, shifts, and repeating-number triangles.
Even though the rows look different, the total count of printed digits is still triangular: 1+2+…+n = n(n+1)/2.
12 people found this page helpful
