C# Number Pattern (Increasing Suffix)

Beginner
5 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A reverse ascending number triangle starts with the peak digit alone, then grows by adding digits on the left: each outer index i prints i through rows.

Remember
Rule: for i from rows down to 1
        for j from i to rows: print j (no space)

5
45
345
2345
12345     ← rows = 5

Follows the ascending triangle in Program 5; next is the reverse-row triangle in Program 7.

How to Solve It

Outer loop counts down from rows to 1. Inner loop prints digits i..rows. End each row with Console.WriteLine().

MethodIdeaBest for
Descending outer + rising startOuter i = rows..1; inner j = i..rows; print jLearning, interviews, exams
Spaced digitsConsole.Write(j + " ") instead of Console.Write(j)Easier reading on each row

Pseudocode

Pseudocode
for i from rows down to 1:
    for j from i to rows:
        print j
    print newline

Cheat sheet

GoalPattern
Pick each rowfor (int i = rows; i >= 1; i--)
Print digitsfor (int j = i; j <= rows; j++) Console.Write(j);
End of rowConsole.WriteLine();
Spaced formConsole.Write(j + " ");
vs Program 5Program 5: 1..i growing right; Program 6: i..rows growing left

Write vs WriteLine

APIEffectUse for
Console.Write(j)Stays on the same lineEach digit on the row
Console.WriteLine()Ends the current lineAfter the inner loop finishes

Print digits with Write (no newline), then call WriteLine() once per row.

Live Preview

Change the row count and the reverse ascending triangle updates instantly — capped at 9 for readable single-digit demos.

Whole numbers from 1 to 9. Tap a chip or type a value — the preview redraws as you go.

Live result rows = 5 · 15 digits
5
45
345
2345
12345

Worked Walkthrough — rows = 5

Trace how a descending outer index makes each new digit appear on the left.

iInner jPrints
55..55
44..545
33..5345
11..512345

Total digits = n(n+1)/2 → O(n²). Compare with Program 5, where digits grow on the right instead.

C# Programs

Three complete programs: fixed rows = 5, TryParse input, and a compact rows = 3 demo. Use View Output to reveal sample results.

Example 1 — Fixed rows = 5

Hard-coded height — outer counts down, inner prints i..rows with no spaces.

C#
using System;

class Program
{
    static void Main()
    {
        int rows = 5;

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

How It Works

1. Outer down. i starts at 5 and moves toward 1 — that start digit moves left each row.

2. Inner up. j runs from i to rows, so every row ends on the same peak digit.

3. Newline. Call Console.WriteLine() only after the inner loop finishes the row.

Example 2 — User Input Rows

Read rows with int.TryParse, validate, then run the same nested loops.

C#
using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter the number of rows: ");
        if (!int.TryParse(Console.ReadLine(), out int rows) || rows <= 0)
        {
            Console.WriteLine("Please enter a positive integer.");
            return;
        }

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

How It Works

1. Prompt and validate. Prefer TryParse so bad input does not throw. Reject non-positive values.

2. Same core. Outer down / inner i..rows matches Example 1 — only rows comes from the user.

3. Safer input tip. Cap demos for readable single-digit output:

Safer input
if (!int.TryParse(Console.ReadLine(), out int rows) || rows < 1 || rows > 9)
{
    Console.WriteLine("Enter a whole number from 1 to 9.");
    return;
}

Example 3 — Compact rows = 3

Same structure with only three rows — easy to trace on paper.

C#
using System;

class Program
{
    static void Main()
    {
        int rows = 3;

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

How It Works

1. Three rows. i = 3 → 3; i = 2 → 23; i = 1 → 123.

2. Trace on paper. Confirm each new digit is prepended on the left, not appended on the right.

3. Scale up next. Once the small demo is clear, use Examples 1–2 for five rows or user input.

Edge Cases & Pitfalls

Check these before calling the solution done.

i = 1..rows

Got Program 5 instead

If the outer loop counts up and the inner prints 1..i, you get 1, 12, 123… Keep outer rows..1 and inner i..rows.

j = 1..i

Wrong digit range

Inner must start at i, not 1. Starting at 1 with a descending outer prints a different shape.

WriteLine inside

Broken rows

If WriteLine() sits inside the inner loop, each digit lands on its own line. Call it only after the row finishes.

rows = 1

Single digit

Output is just 1 — a good sanity check for input validation.

rows > 9

Multi-digit width

Digits 10+ make tight rows hard to read. Cap demos at 9 or switch to spaced Write(j + " ").

TryParse

Validate input

Prefer int.TryParse and require rows > 0 before looping — bad input should not throw.

Time and Space Complexity

ProgramTimeExtra space
Fixed / input (Examples 1–2)O(n²)O(1)
Compact rows = 3 (Example 3)O(n²)O(1)

Total digits printed = 1 + 2 + … + n = n(n+1)/2 → O(n²) time. Only a few loop variables are needed.

Key Takeaways

  • Grow from the left: outer rows..1, inner i..rows.
  • Same peak every row: every line ends at rows; only the start digit changes.
  • Break the row: Console.Write(j) in the inner loop; WriteLine() after it.
  • Complexity: O(n²) time from n(n+1)/2 digits; O(1) extra space.

One line: count i down from rows, print j from i to rows, then newline.

Frequently Asked Questions

The outer loop begins at i = rows. The inner loop prints j from i to rows, so the first row prints only that single digit.
When i = 1, the inner loop runs j from 1 to rows — printing 1, 2, 3, 4, 5 on one line.
Each row adds one more digit on the left: row i prints digits i through rows, e.g. rows=5 gives 5, 45, 345, 2345, 12345.
Program 5 counts the outer loop up and prints 1..i. Program 6 counts the outer loop down and prints i..rows — digits grow from the left instead of the right.
Console.Write(j) stays on the same line for each digit. Console.WriteLine() ends the row after the inner loop finishes.
Change rows or read it from user input with int.TryParse — see Example 2.
O(n²) for n rows because total prints are 1 + 2 + ... + n = n(n+1)/2.
One row prints a single digit 1 — the inner loop runs j from 1 to 1 only once.

Did you know?

The outer loop starts from rows down to 1, and the inner loop prints i..rows — producing 5, 45, 345, and so on. Total prints still grow as O(n²).

Next: Reverse Row Number Triangle

Continue with rows that count down (1, 21, 321) instead of growing leftward.

Program 7 tutorial →

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