Descending Repeating Number Triangle in C#

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

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:

Output
5
44
333
2222
11111
1

Complete C# Program

The outer loop decreases the digit. The inner loop repeats it the required number of times for that row.

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

🧠 How It Works

1

Set the size

int rows = 5; decides the starting digit and the triangle height.

Setup
2

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).

Row control
3

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.

Repeat digit
4

New line

Console.WriteLine() ends each row so the next row starts on a new line.

Line break
=

Repeating number triangle

Total prints are 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 using Console.ReadLine() so the pattern can scale:

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

💡 Tips for Enhancement

Try These

  • Validate input with int.TryParse before converting
  • Add spaces between digits with Console.Write(i + " ")
  • Flip it to an ascending repeating pattern by counting i upward 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.ToInt32 without handling invalid input
  • Mixing the inner-loop bounds (it controls the repeat count)

Key Takeaways

1

The digit decreases from rows down to 1, but the repeat count increases.

2

The inner loop controls how many times the digit prints on each line.

3

Total prints follow triangular numbers: n(n+1)/2.

4

Reading rows from the console makes your pattern program reusable.

❓ Frequently Asked Questions

Because the inner loop repeats from rows down to i. When i becomes 1, the inner loop runs rows times, so 1 is repeated the most.
Yes. Set rows to any positive integer. The first row prints that number once and the last row prints 1 repeated rows times.
O(n²) for 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.

All Number Patterns →
Did you know?

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.

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