Number Triangle with Increasing Start in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

How to print a number triangle with increasing start in C. The first row prints 1 to rows. The next row starts from 2, then 3, and so on—creating a clean diagonal effect.

The key idea is simple: keep the outer loop for rows, but start the inner loop from the current row index i (not from 1).

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
12345
2345
345
45
5
1

Complete C Program

The outer loop decides the starting number. The inner loop prints from i to rows.

c
#include <stdio.h>

int main() {
    int rows = 5;
    int i, j;

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

    return 0;
}

🧠 How It Works

1

Row count

rows = 5 controls the height and also the largest number printed.

Setup
2

Outer loop (row start)

i goes from 1 to rows. Each value of i becomes the first number on that row.

Start increases
3

Inner loop (print i..rows)

j starts at i and runs to rows, printing a decreasing-length sequence: 1..5, 2..5, 3..5, ...

Diagonal effect
4

New line

printf("\n") completes the current row.

Line break
=

Triangle with increasing start

Total numbers printed: n+(n-1)+…+1 = n(n+1)/2, so time complexity is O(n²).

2

Variation — User Input Version

Read the row count at runtime with scanf():

c
#include <stdio.h>

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

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Accept row count from the user with scanf()
  • Add spaces between numbers with printf("%d ", j)
  • Print a reverse version by counting j down from rows
  • Right-align the output by printing leading spaces before each row
  • Replace digits with letters to build alphabet patterns

Avoid

  • Starting the inner loop from 1 (you’ll lose the diagonal effect)
  • Forgetting printf("\n") after each row
  • Using non-positive rows without validating input

Key Takeaways

1

The start number increases because the inner loop begins at j = i.

2

Row i prints i through rows, so each lower row is shorter.

3

Total prints are n(n+1)/2, so the program runs in O(n²) time.

4

This is a close cousin of the descending number triangle—only the inner-loop start changes.

❓ Frequently Asked Questions

Each next row begins with a larger number: 1, then 2, then 3, and so on, creating the diagonal effect.
Because i is the row index. Starting from i makes the row begin one number later each time: row 1 prints 1..rows, row 2 prints 2..rows, etc.
Count j down from rows to i: for (j = rows; j >= i; --j). Print j inside the loop.
O(n²) for n rows because the total prints are n+(n-1)+…+1 = n(n+1)/2.

Keep Going with Number Patterns

Small tweaks to loop start/end values can create completely new shapes—practice a few more and you’ll spot patterns instantly.

All Number Patterns →
Did you know?

This pattern and Program 1 print the same total amount of numbers for a given n. Both print n(n+1)/2 numbers—the difference is only which numbers appear on each row.

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