Incremental Number Triangle in C

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

What You’ll Learn

How to print an incremental number triangle where each row starts with the row index and each next value is computed using a decreasing increment.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
1

Complete C Program

We print one row at a time. After printing a value, we update it with currNum += (rows - j).

c
#include <stdio.h>

int main() {
    int rows = 5;
    int num = 1;

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

    return 0;
}

🧠 How It Works

1

Set rows and starting value

rows controls the height and num controls the first number of each row.

Setup
2

Start each row with currNum

currNum = num ensures row 1 starts at 1, row 2 at 2, etc.

Row start
3

Decreasing increment across the row

After each print we add (rows - j). With rows=5 this produces 4,3,2,1….

Increment
=

Incremental triangle

This is a good exercise for combining nested loops with arithmetic sequences.

2

Variation — User Input Version

Read the number of rows using scanf().

c
#include <stdio.h>

int main() {
    int rows;
    int num = 1;

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Change the increment formula to generate new sequences
  • Use formatted printing to align columns
  • Compute and print each row’s sum

Avoid

  • Using rows <= 0 without validating input
  • Forgetting to reset currNum at the start of each row

Key Takeaways

1

Row i prints i values, forming a triangle.

2

Each row starts with the row number.

3

The increment decreases across the row via (rows - j).

4

Total work is 1+2+…+n, so runtime is O(n²).

❓ Frequently Asked Questions

Because we add (rows - j), and as j increases, rows - j decreases.
Yes. Increase rows or use the input version and enter a larger number.
O(n²) for n rows.

Explore More C Number Patterns!

Try other arithmetic and triangle patterns to strengthen your loop skills.

All Number Patterns →
Did you know?

The update currNum += (rows - j) is an easy way to create a decreasing-step arithmetic progression across 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