C# Number Triangle Pattern (Increasing Jump)

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

What Is This Pattern?

An increasing jump number triangle prints a growing triangle where each row starts at i, then jumps forward by a shrinking step m.

Remember
Rule: print i, then jump with m = n-1… down

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15   ← 5 rows

In C# you print i first, set m = rows - 1 and k = i + m, then in the inner loop print k, do m--, and update k = k + m. Compare with Program 20, where a single counter just increments by 1.

How to Solve It

One nested-loop idea with two useful variants — default step and custom step.

MethodIdeaBest for
Decreasing stepPrint i, then jump with m = rows - 1 shrinking each timeLearning, interviews, exams
Custom stepSame loops, but set a fixed initial mPractice variants

Pseudocode

Pseudocode
for i from 1 to rows:
    print i
    m = rows - 1
    k = i + m
    for j from 1 to i - 1:
        print k
        m = m - 1
        k = k + m
    print newline

Cheat sheet

GoalPattern
Grow the rowfor (i = 1; i <= rows; i++)
Print the row startConsole.Write(i + " ");
Set first jumpm = rows - 1; k = i + m;
Print remaining jumpsfor (j = 1; j < i; j++) then m--; k = k + m;
End the rowConsole.WriteLine();

Write vs WriteLine

APIEffectUse for
Console.WriteStays on the same lineEach number i or k plus a space
Console.WriteLineEnds the current lineAfter the inner loop

Live Preview

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

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

Live result 5 rows · 15 numbers
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Worked Walkthrough — rows = 4

Trace each row: the start digit i, the initial step m = 3, and the jump values.

iFirst jumpPrinted rowCount
1—11
2k = 2+3 = 52 52
36, then m-- → 83 6 83
47, 9, 104 7 9 104

Total numbers are 1+2+3+4 = 10 — the triangular number n(n+1)/2.

C# Programs

Three complete programs: fixed height, row-count input, and a custom initial step. Use View Output for sample results.

Example 1 — Fixed rows = 5

Print i, then jump with a shrinking step starting at rows - 1.

C#
using System;

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

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

                m = rows - 1;
                k = i + m;

                for (j = 1; j < i; j++)
                {
                    Console.Write(k + " ");
                    m--;
                    k = k + m;
                }

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Print the start. Each row begins with Console.Write(i + " ").

2. Jump with m. Set m = rows - 1 and k = i + m. After each print, do m-- then k = k + m.

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

Example 2 — User Input

Read the row count at runtime. Prefer int.TryParse in real apps so bad input does not throw.

C#
using System;

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

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

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

                m = rows - 1;
                k = i + m;

                for (j = 1; j < i; j++)
                {
                    Console.Write(k + " ");
                    m--;
                    k = k + m;
                }

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Validate rows. TryParse rejects non-numeric input; require rows >= 1.

2. Scale the step. m = rows - 1 becomes 3 for four rows, producing 1 / 2 5 / 3 6 8 / 4 7 9 10.

Example 3 — Custom Initial Step m = 3

Keep rows = 4 but hard-code the initial step instead of rows - 1.

C#
using System;

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

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

                m = 3;
                k = i + m;

                for (j = 1; j < i; j++)
                {
                    Console.Write(k + " ");
                    m--;
                    k = k + m;
                }

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Fix the step. Replace m = rows - 1 with a constant m = 3.

2. Same update logic. The inner loop still does m-- then k = k + m after each print.

Edge Cases & Pitfalls

Check these before calling the solution done.

forget m--

Constant step forever

Always do m-- then k = k + m after printing k, or jumps stay the same size.

wrong bound

j <= i instead of j < i

You already printed i; the inner loop should run only i - 1 times.

WriteLine early

WriteLine(k) inside the inner loop

That puts each number on its own line. Use Write; call WriteLine() only after the row finishes.

rows = 1

Single 1

Output is just 1 — the inner loop never runs.

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
Nested loops (Examples 1–2)O(n²)O(1)
Custom step (Example 3)O(n²)O(1)

There are n rows printing 1+2+…+n numbers, so total work is n(n+1)/2.

Key Takeaways

  • Rule: print i, then jump with m = rows - 1 shrinking after each value.
  • Update order: always m-- then k = k + m after printing k.
  • Write vs WriteLine: numbers stay on the line; WriteLine advances after each row.
  • Next step: Program 22 prints rows with odd lengths only.

One line: print i, set m = rows - 1 and k = i + m, then loop with m-- and k = k + m.

Frequently Asked Questions

Because the step variable m starts at rows - 1 and decreases after each printed number. Each next value is computed by adding the current m, so the jumps shrink across the row.
m is the step size used to compute the next printed number in the row. It decreases each time, changing the increment between consecutive outputs.
Row 2 prints i = 2 first. Then m = 4 and k = i + m = 6 — the inner loop prints k once, giving 2 6.
Console.Write stays on the same line. Console.WriteLine ends the current line. Numbers use Write(i + " ") or Write(k + " "); the row break uses WriteLine after the inner loop.
Total prints are 1+2+…+n = n(n+1)/2 — row i prints exactly i values.
Yes. Set m to a custom value instead of rows - 1 (see Example 3) — smaller steps produce tighter jumps.
O(n²) for n rows because total Console.Write calls equal n(n+1)/2.
Prefer int.TryParse(Console.ReadLine(), out rows) so bad input does not throw FormatException.
The outer loop never runs, so nothing is printed. Validate and prompt again if you want a clear user message.

Did you know?

Each row starts at i, then adds a decreasing step m to compute the next value. As m shrinks after each print, the jumps get smaller toward the end of the row — total prints still equal n(n+1)/2 for n rows.

Next: Odd-Length Number Rows

Print rows whose lengths grow by odd counts: 1, 3, 5, …

Program 22 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