Left-Shifted Sequential Number Triangle (Start from 1) in C

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

What You’ll Learn

How to print a left-shifted sequential number triangle in C that starts from 1. Each row begins one number later than the previous row, and values in the row increase sequentially.

It’s a clean nested-loop pattern: the outer loop controls rows, and the inner loop prints i+1 numbers in each row.

⭐ Pattern Output

For rows = 5 and start_num = 1, the pattern looks like this:

Output
1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
1

Complete C Program

We compute num = start_num + i at the start of each row, then print i+1 values while incrementing num.

c
#include <stdio.h>

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

    for (int i = 0; i < rows; i++) {
        int num = start_num + i;

        for (int j = 0; j <= i; j++) {
            printf("%d ", num);
            num++;
        }

        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Set rows and start value

We pick rows = 5 and set start_num = 1.

Setup
2

Outer loop controls rows

for (i = 0; i < rows; i++) decides which row we are printing.

Row control
3

Shift the row start

We compute num = start_num + i so the row starts become 1, 2, 3, 4, 5.

Left-shift
4

Inner loop prints i+1 values

for (j = 0; j <= i; j++) prints 1 value on the first row, 2 values on the second row, and so on. We increment num++ after each print.

Number printing
=

Left-shifted sequential triangle (from 1)

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

2

Variation — User Input Version

Accept both the row count and the starting number using scanf():

c
#include <stdio.h>

int main() {
    int rows, start_num;

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

    printf("Enter the starting number: ");
    scanf("%d", &start_num);

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Change start_num to generate a new starting point
  • Use printf("%02d ", num) for aligned columns
  • Remove trailing spaces by printing a space only when j < i
  • Create a right-aligned version by printing leading spaces per row
  • Replace numbers with letters to create alphabet patterns

Avoid

  • Forgetting printf("\n") after each row
  • Using invalid input values without validation
  • Not resetting num at the beginning of each row
  • Swapping loop roles (outer loop rows, inner loop columns)

Key Takeaways

1

The outer loop sets the row index and row length.

2

The row start is computed as start_num + i.

3

The inner loop prints sequential values by incrementing num.

4

Overall runtime grows as O(n²) with the number of rows.

❓ Frequently Asked Questions

Set start_num = 1. Each row will then start at 1+i.
Because for row index i = 1, we compute num = 1 + 1 which is 2.
Yes. Print a space only when j < i, or print the last value separately without a trailing space.
O(n²) for n rows: total prints are 1+2+…+n = n(n+1)/2.

Explore More C Number Patterns!

Keep practicing nested loops with more number pattern variations—from triangles to pyramids.

All Number Patterns →
Did you know?

When you print n rows, you print n(n+1)/2 values in total. That’s why these nested-loop patterns often have O(n²) runtime.

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