C Number Triangle Pattern (Starting from 11)

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

What Is This Pattern?

An increasing triangle from 11 prints values from the formula 9 + i + j. Row i has i numbers, each separated by a space, growing left-aligned.

Remember
Rule: for i from 1 to rows
      for j from 1 to i:
        print (9 + i + j) + space

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

Nested loops plus one arithmetic formula. Follows the number-star diamond in Program 31; next is Program 33 (same shape, formula starts at 1).

How to Solve It

Start with fixed rows = 5 and base 9, then generalize both with scanf — optionally demo a smaller count for tracing.

MethodIdeaBest for
Fixed formulaPrint 9 + i + j for j = 1..iLearning, interviews, exams
Custom baseSame loops; baseVal + i + j from scanfShifting the whole triangle

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
Walk each rowfor (i = 1; i <= rows; i++)
Grow row lengthfor (j = 1; j <= i; j++)
Print value + spaceprintf("%d ", 9 + i + j);
End the rowprintf("\n");
Custom baseprintf("%d ", baseVal + i + j);

Printing Numbers vs Starting a New Line

APIEffectUse for
printf("%d ", 9 + i + j)Stays on the same lineEach value plus a separator space
printf("\n")Ends the current lineAfter the inner loop

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

Live Preview

Change the row count and the triangle updates instantly — base stays at 9 so the first value is always 11.

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 outer-loop value of i and list the formula results for j = 1..i.

iValues (9 + i + j)Printed row
11111
212, 1312 13
313, 14, 1513 14 15
414, 15, 16, 1714 15 16 17

Total values for n rows = n(n + 1)/2 (here 4 × 5 / 2 = 10). That triangular sum is why time is O(n²).

C Programs

Three complete programs: fixed rows, custom base via scanf, and a small demo. Use View Output to reveal sample results.

Example 1 — Fixed rows = 5

Hard-coded row count — classic 9 + i + j formula.

C
#include <stdio.h>

int main(void)
{
    int i, j;

    for (i = 1; i <= 5; i++)
    {
        for (j = 1; j <= i; j++)
            printf("%d ", 9 + i + j);

        printf("\n");
    }

    return 0;
}

How It Works

1. Outer loop grows i. i runs from 1 to 5 — one longer row each pass.

2. Inner loop prints the formula. j runs from 1 to i; each value is 9 + i + j plus a space.

3. Newline. printf("\n") ends the row after the inner loop.

When i = 1 you get 11; when i = 3 you get 13 14 15.

Example 2 — Custom Base and Rows

Read rows and baseVal with scanf. The formula becomes baseVal + i + j.

C
#include <stdio.h>

int main(void)
{
    int rows, baseVal;
    int i, j;

    printf("Enter rows: ");
    scanf("%d", &rows);
    printf("Enter base: ");
    scanf("%d", &baseVal);
    if (rows < 1) rows = 1;

    for (i = 1; i <= rows; i++)
    {
        for (j = 1; j <= i; j++)
            printf("%d ", baseVal + i + j);

        printf("\n");
    }

    return 0;
}

How It Works

1. Prompt for both inputs. rows sets height; baseVal replaces the hard-coded 9.

2. Same nested core. Only the formula offset changes — first value is always baseVal + 2.

3. Safer input tip. Unchecked scanf leaves variables uninitialized on bad input. Prefer:

Safer input
if (scanf("%d", &rows) != 1 || rows < 1)
{
    printf("Enter a positive whole number of rows.\n");
    return 1;
}
if (scanf("%d", &baseVal) != 1)
{
    printf("Enter a whole number base.\n");
    return 1;
}

Example 3 — Compact rows = 3

Same formula with a smaller row count for quick paper tracing.

C
#include <stdio.h>

int main(void)
{
    int rows = 3;
    int i, j;

    for (i = 1; i <= rows; i++)
    {
        for (j = 1; j <= i; j++)
            printf("%d ", 9 + i + j);

        printf("\n");
    }

    return 0;
}

How It Works

1. Same structure. Only rows changes from 5 to 3 — the formula stays 9 + i + j.

2. Trace on paper. For i = 2: 9+2+1 = 12, 9+2+2 = 13 → 12 13.

3. Scale up next. Once the small demo is clear, use Examples 1–2 for five rows or a custom base.

Edge Cases & Pitfalls

Check these before calling the solution done.

wrong formula

Starts at the wrong number

Using i + j or i + j - 1 changes the first value. Keep 9 + i + j for a start at 11 (or swap in baseVal).

no space

Glued numbers

printf("%d", 9 + i + j) without a space merges values like 1213. Always append a space in the format string.

\n inside

Broken rows

If printf("\n") sits inside the inner loop, each value lands on its own line. Call the newline only after the row finishes.

j to rows

Rectangle instead of triangle

Looping j to rows instead of i prints the same count every line. Inner bound must be i.

rows = 1

Smallest triangle

Output is a single 11 — a good sanity check.

scanf

Check both return values

Example 2 reads two integers. Test each scanf(...) == 1 so neither variable stays uninitialized.

Time and Space Complexity

ProgramTimeExtra space
Fixed / input (Examples 1–2)O(rows²)O(1)
Small demo (Example 3)O(rows²)O(1)

Total values = n(n + 1)/2 — quadratic in n. For rows = 5 that is 15 printed numbers.

Key Takeaways

  • Rule: for each i, print 9 + i + j for j = 1..i.
  • Base offset: 9 makes the first value 11; swap in baseVal to shift the triangle.
  • Break the row: call printf("\n") only after the inner loop.
  • Complexity: O(n²) time from n(n + 1)/2 values; O(1) extra space.

One line: for i from 1 to rows, print 9 + i + j for j = 1..i, then printf("\n").

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).
printf("%d ", 9 + i + j) keeps values separated on the same row. printf("\n") 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.
Check scanf's return value and reject non-positive row counts so the outer loop has a valid range.
Yes — printf("%d ", baseVal + i + j) lets the user pick any starting offset — see Example 2.

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 from 1

Same growing shape — switch the formula to i + j - 1 so the first value is 1.

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