C# Number Triangle Pattern (Starting from 11)

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

What Is This Pattern?

An increasing number triangle from 11 prints a growing left-aligned triangle where each value is 9 + i + j — so the first cell is 11, not 1.

Remember
Rule: print (9 + i + j) with a trailing space

11
12 13
13 14 15
14 15 16 17
15 16 17 18 19   ← 5 rows

In C# the outer loop grows the row length; the inner loop prints i values per row. Change the base 9 to shift the whole triangle.

How to Solve It

One nested-loop idea with a fixed or custom base offset.

MethodIdeaBest for
Fixed base 9Print 9 + i + j on each cellLearning, interviews, exams
Custom baseReplace 9 with a user-supplied offsetPractice / variants

Pseudocode

Pseudocode
for i from 1 to rows:
    for j from 1 to i:
        print (9 + i + j) and a space
    print newline

Cheat sheet

GoalPattern
Grow the rowfor (i = 1; i <= rows; i++)
Print i valuesfor (j = 1; j <= i; j++)
Cell valueConsole.Write((9 + i + j) + " ");
Custom baseConsole.Write((baseVal + i + j) + " ");
End the rowConsole.WriteLine();

Write vs WriteLine

APIEffectUse for
Console.WriteStays on the same lineEach number + space
Console.WriteLineEnds the current lineAfter the inner loop

Live Preview

Change the row count and the triangle updates instantly — including the total value count.

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

Live result 5 rows · 15 values
11 
12 13 
13 14 15 
14 15 16 17 
15 16 17 18 19 

Worked Walkthrough — rows = 4

Trace each cell with the formula 9 + i + j.

iValues of jPrinted row
19+1+1 = 1111
212, 1312 13
313, 14, 1513 14 15
414 … 1714 15 16 17

Row i always prints i numbers. Notice consecutive rows overlap in values — that is expected from the formula.

C# Programs

Three complete programs: fixed height, custom base with user input, and a compact 3-row demo. Use View Output for sample results.

Example 1 — Fixed rows = 5

Nested loops print 9 + i + j with a trailing space on each cell.

C#
using System;

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

            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= i; j++)
                    Console.Write((9 + i + j) + " ");

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Outer loop. i grows from 1 to 5 — each pass adds one more number to the row.

2. Formula. 9 + i + j yields 11 on the first cell, then climbs across each row.

3. Newline. WriteLine() after the inner loop starts the next longer row.

Example 2 — User Input (rows + base)

Read the row count and a custom base offset so the triangle can start anywhere.

C#
using System;

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

            Console.Write("Enter rows: ");
            if (!int.TryParse(Console.ReadLine(), out rows) || rows < 1)
            {
                Console.WriteLine("Please enter a positive whole number for rows.");
                return;
            }

            Console.Write("Enter base: ");
            if (!int.TryParse(Console.ReadLine(), out baseVal))
            {
                Console.WriteLine("Please enter a whole number for base.");
                return;
            }

            for (i = 1; i <= rows; i++)
            {
                for (j = 1; j <= i; j++)
                    Console.Write((baseVal + i + j) + " ");

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Validate input. TryParse handles both prompts; require rows >= 1.

2. Same formula. baseVal + i + j with base 9 matches Example 1; try base 10 to start at 12.

Example 3 — Compact rows = 3

A smaller fixed demo — same formula, easier to trace by hand.

C#
using System;

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

            for (i = 1; i <= rows; i++)
            {
                for (j = 1; j <= i; j++)
                    Console.Write((9 + i + j) + " ");

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Same rules. Outer grows length; inner prints 9 + i + j with a space.

2. Quick check. Three rows end at 13 14 15.

Edge Cases & Pitfalls

Check these before calling the solution done.

wrong formula

Print i + j without the base

That starts at 2, not 11. Keep the offset: 9 + i + j.

missing space

Forget the trailing space

Numbers glue together (1213). Always append " " in Write.

WriteLine early

WriteLine inside the inner loop

That puts each number on its own line. Call WriteLine() only after the inner loop.

rows = 1

Single 11

Output is just 11 (plus a trailing space).

rows ≤ 0

Empty output

The outer loop never runs. Validate and prompt again for clearer UX.

Bad input

Convert.ToInt32 throws

Prefer int.TryParse so non-numeric input does not crash the program.

Time and Space Complexity

ProgramTimeExtra space
Fixed / compact (Examples 1, 3)O(n²)O(1)
Custom base (Example 2)O(n²)O(1)

Total printed values are 1 + 2 + … + n = n(n+1)/2, which is quadratic in n.

Key Takeaways

  • Rule: print 9 + i + j with a trailing space on each cell.
  • Shape: row i prints exactly i numbers — a classic left triangle.
  • Write vs WriteLine: numbers stay on the line; WriteLine advances after each row.
  • Next step: Program 33 uses i + j - 1 so the triangle starts at 1.

One line: for each row i, print i values of 9 + i + j to build an increasing triangle from 11.

Frequently Asked Questions

Because the printed value is 9 + i + j. On the first row i = 1 and j = 1, so 9 + 1 + 1 = 11.
It is a base offset. Change 9 to any base value to shift the entire triangle — see Example 2.
Program 32 uses 9 + i + j (starts at 11). Program 33 uses i + j - 1 (starts at 1).
Console.Write((9 + i + j) + " ") keeps values separated on the same row. WriteLine ends the row.
Replace 5 with rows in the outer loop bound — see Example 2.
O(n²) for n rows because total prints are 1 + 2 + ... + n = n(n+1)/2.
Prefer int.TryParse(Console.ReadLine(), out rows) so bad input does not throw FormatException.
Only one row prints — a single 11.
Yes — Console.Write((baseVal + i + j) + " ") lets the user pick any starting offset.

Did you know?

Each printed value is computed as 9 + i + j. Row i = 1 prints 11; row i = 2 prints 12 and 13 — a left-shifted increasing triangle.

Next: Increasing Triangle (i + j - 1)

Same triangle shape, but the formula starts at 1 instead of 11.

Program 33 tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

6 people found this page helpful