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
printf("%d ", 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
printf("\n");
Printing Numbers vs Starting a New Line
API
Effect
Use for
printf("%d ", i) / printf("%d ", k)
Stays on the same line
Each number plus a space
printf("\n")
Ends the current line
After the inner loop
Print all numbers without a newline, then end the row once.
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, scanf 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
#include <stdio.h>
int main(void)
{
int rows = 5;
int i, j, k, m;
for (i = 1; i <= rows; i++)
{
printf("%d ", i);
m = rows - 1;
k = i + m;
for (j = 1; j < i; j++)
{
printf("%d ", k);
m--;
k = k + m;
}
printf("\n");
}
return 0;
}
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 printf("%d ", i).
2. Jump with m. Set m = rows - 1 and k = i + m. After each print, do m-- then k = k + m.
3. Newline.printf("\n") after the inner loop starts the next longer row.
Example 2 — User Input
Read the row count with scanf and reject non-positive values.
C
#include <stdio.h>
int main(void)
{
int rows;
int i, j, k, m;
printf("Enter the number of rows: ");
if (scanf("%d", &rows) != 1 || rows < 1)
{
printf("Please enter a positive whole number.\n");
return 1;
}
for (i = 1; i <= rows; i++)
{
printf("%d ", i);
m = rows - 1;
k = i + m;
for (j = 1; j < i; j++)
{
printf("%d ", k);
m--;
k = k + m;
}
printf("\n");
}
return 0;
}
Output (when user enters 4)
1
2 5
3 6 8
4 7 9 10
How It Works
1. Validate rows. Check scanf; 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
#include <stdio.h>
int main(void)
{
int rows = 4;
int i, j, k, m;
for (i = 1; i <= rows; i++)
{
printf("%d ", i);
m = 3;
k = i + m;
for (j = 1; j < i; j++)
{
printf("%d ", k);
m--;
k = k + m;
}
printf("\n");
}
return 0;
}
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.
newline early
printf("%d\n", k) inside the inner loop
That puts each number on its own line. Use printf("%d ", k); call printf("\n") 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
Unchecked scanf
Always check scanf’s return value so non-numeric input does not leave rows uninitialized.
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.
printf vs newline: numbers stay on the line; printf("\n") 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.
printf("%d ", k) stays on the same line. printf("\n") ends the current line. Numbers use printf with a trailing space; the row break uses printf("\n") 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 printf calls equal n(n+1)/2.
Check scanf's return value: if (scanf("%d", &rows) != 1) handle bad input. Unchecked scanf leaves rows uninitialized on failure.
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.