Left-Aligned Descending Number Triangle in C#

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

What You’ll Learn

How to print a left-aligned descending number triangle in C#. Each row starts from the maximum number (rows) and counts down to a changing stop value, producing 54321, 5432, 543, 54, and 5.

The inner loop counts downward and always begins from rows, so every row starts with the same maximum digit while the line gets shorter.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
54321
5432
543
54
5
1

Complete C# Program

Outer loop increases the stop value; inner loop prints from rows down to i.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int rows = 5;
            int i, j;

            for (i = 1; i <= rows; i++)
            {
                for (j = rows; j >= i; j--)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Set the height

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

Setup
2

Outer loop (row index)

for (i = 1; i <= rows; i++) increases the stopping point for each row.

Row control
3

Inner loop (print rows..i)

for (j = rows; j >= i; j--) prints from 5 down to i. Since i grows each row, fewer digits get printed.

Descending print
4

New line

Console.WriteLine() moves to the next row.

Line break
=

Left-aligned descending triangle

Total digits printed are 5+4+3+2+1 = n(n+1)/2 for n rows, so time complexity is O(n²).

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 = 1; i <= rows; i++)
            {
                for (int j = rows; j >= i; j--)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Validate input with int.TryParse to avoid crashes
  • Add spaces between digits for readability
  • Swap bounds to print from rows down to 1 on every row (fixed width)
  • For a right-aligned look in the console, pad shorter rows with leading spaces before the digits

Avoid

  • Forgetting Console.WriteLine() after each row
  • Using Convert.ToInt32 without handling invalid input
  • Incrementing j (this pattern needs a countdown)

Key Takeaways

1

Each row begins at rows and stops at i.

2

The outer loop increases i, so each row prints fewer digits.

3

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

4

This is a useful pattern for practicing variable inner-loop stop conditions.

❓ Frequently Asked Questions

On the last row, i = rows, so the inner loop prints just rows once.
Program 3 prints from i down to 1. This program prints from rows down to i, so each row always starts with the maximum digit.
O(n²) for n rows since you print n(n+1)/2 digits.

Explore More C# Number Patterns!

Keep practicing nested loops with inversions, alignments, and alternating number patterns.

All Number Patterns →
Did you know?

When the inner loop prints from rows down to i, the number of printed digits is still triangular: 5+4+3+2+1. Only the starting value changes.

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