Reverse Ascending Number Triangle in C#

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

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:

Output
5
45
345
2345
12345
1

Complete C# Program

The outer loop counts down from rows to 1. The inner loop prints from i up to rows.

C#
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

1

Pick the height

int rows = 5; sets both the maximum digit and the number of rows.

Setup
2

Outer loop (descending start)

for (i = rows; i >= 1; i--) moves the starting value leftward from 5 down to 1.

Row control
3

Inner loop (print i..rows)

for (j = i; j <= rows; j++) prints from the current start to the maximum digit.

Number printing
4

New line

Console.WriteLine() moves to the next row.

Line break
=

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.

2

Variation — User Input Version

Read the row count at runtime:

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 = 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.TryParse before converting
  • Add spaces with Console.Write(j + " ") for readability
  • Flip it to a left-shifted version by starting the inner loop at i and ending at rows (Program 2)
  • Right-align the rows by printing leading spaces before the numbers

Avoid

  • Forgetting Console.WriteLine() after each row
  • Using Convert.ToInt32 without handling invalid input
  • Mixing up loop bounds (the inner loop must start at i)

Key Takeaways

1

The outer loop moves the starting value from rows down to 1.

2

The inner loop prints from i to rows, growing each row.

3

Total digits printed are triangular: n(n+1)/2.

4

Adjusting only the loop start values can dramatically change the output shape.

❓ Frequently Asked Questions

Because the starting value i decreases from 5 to 1, so the inner loop prints more digits each next row.
Program 5 prints 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.
O(n²) for n rows since total prints are n(n+1)/2.

Explore More C# Number Patterns!

Keep practicing loop bounds with inversions, shifts, and repeating-number triangles.

All Number Patterns →
Did you know?

Even though the rows look different, the total count of printed digits is still triangular: 1+2+…+n = n(n+1)/2.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful