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 startprintf("%d ", i);
Set first jumpm = rows - 1; k = i + m;
Print remaining jumpsfor (j = 1; j < i; j++) then m--; k = k + m;
End the rowprintf("\n");

Printing Numbers vs Starting a New Line

APIEffectUse for
printf("%d ", i) / printf("%d ", k)Stays on the same lineEach number plus a space
printf("\n")Ends the current lineAfter the inner loop

Print all numbers without a newline, then end the row once.

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, 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;
}

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;
}

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;
}

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.

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.
  • 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.

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