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.
Approach
How to Solve It
One nested-loop idea with two useful variants — default step and custom step.
Method
Idea
Best for
Decreasing step
Print i, then jump with m = rows - 1 shrinking each time
Learning, interviews, exams
Custom step
Same loops, but set a fixed initial m
Practice 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
Goal
Pattern
Grow the row
for (i = 1; i <= rows; i++)
Print the row start
Console.Write(i + " ");
Set first jump
m = rows - 1; k = i + m;
Print remaining jumps
for (j = 1; j < i; j++) then m--; k = k + m;
End the row
Console.WriteLine();
Write vs WriteLine
API
Effect
Use for
Console.Write
Stays on the same line
Each number i or k plus a space
Console.WriteLine
Ends the current line
After the inner loop
Try it
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 result5 rows · 15 numbers
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
Trace
Worked Walkthrough — rows = 4
Trace each row: the start digit i, the initial step m = 3, and the jump values.
i
First jump
Printed row
Count
1
—
1
1
2
k = 2+3 = 5
2 5
2
3
6, then m-- → 8
3 6 8
3
4
7, 9, 10
4 7 9 10
4
Total numbers are 1+2+3+4 = 10 — the triangular number n(n+1)/2.
Code
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();
}
}
}
}
Output
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
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();
}
}
}
}
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();
}
}
}
}
Output
1
2 5
3 6 8
4 7 9 10
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.
Analysis
Time and Space Complexity
Program
Time
Extra 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.
Remember
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.