Number Triangle with Increasing Start in C

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:
12345
2345
345
45
5Complete C Program
The outer loop decides the starting number. The inner loop prints from i to rows.
#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
Row count
rows = 5 controls the height and also the largest number printed.
Outer loop (row start)
i goes from 1 to rows. Each value of i becomes the first number on that row.
Inner loop (print i..rows)
j starts at i and runs to rows, printing a decreasing-length sequence: 1..5, 2..5, 3..5, ...
New line
printf("\n") completes the current row.
Triangle with increasing start
Total numbers printed: n+(n-1)+…+1 = n(n+1)/2, so time complexity is O(n²).
Variation — User Input Version
Read the row count at runtime with scanf():
#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
jdown fromrows - 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
The start number increases because the inner loop begins at j = i.
Row i prints i through rows, so each lower row is shorter.
Total prints are n(n+1)/2, so the program runs in O(n²) time.
This is a close cousin of the descending number triangle—only the inner-loop start changes.
❓ Frequently Asked Questions
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.j down from rows to i: for (j = rows; j >= i; --j). Print j inside the loop.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.
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.
12 people found this page helpful
