The rising start number triangle grows downwards and every row ends at 5: 5, then 45, then 345, until the last row is 12345. Each new row adds one smaller number at the front.
Quick answer: Row i prints i numbers, from n β i + 1 up to n. So the value at position j is n β i + j. On row 3 that is 3, 4, 5. Every row ends at n and the start moves one step down each row.
This program is part of the Number Patterns collection.
Table of contents8 sections
Rising Start Number Triangle output
Output (n = 5):
5 45 345 2345 12345

Same shape, other characters: the Alternating Star and Hash Triangle, Descending Number Triangle, Descending Repeated Number Triangle, Number Right Triangle and Repeated Number Triangle programs draw this same outline with different characters. Putting them side by side shows which part of the loop decides the shape and which part decides what is printed.
How the rising start number triangle works
Turn the suffix number triangle (12345, 2345, 345) upside down and you get this pattern. The row length is i, so the triangle grows, and the first number is chosen so that the row always ends at n: start at n β i + 1, take i numbers, and you finish exactly at n.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
inumbers (valuen β i + j). - Move to the next line.
Key takeaways
- Every row ends at
n; only the starting number changes. - The starting number
n β i + 1goes down by one each row. - The value
n β i + jrises by one per column. - Right-aligning the rows (with
n β ispaces) lines up all the 5s in the last column.
Rising Start Number Triangle in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
printf("%d", n - i + j);
printf("\n");
}
return 0;
}Rising Start Number Triangle in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
cout << n - i + j;
cout << endl;
}
return 0;
}Rising Start Number Triangle in Java
public class RisingStartNumberTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print(n - i + j);
System.out.println();
}
}
}Rising Start Number Triangle in Python
n = 5
for i in range(1, n + 1):
for j in range(1, i + 1):
print(n - i + j, end="")
print()Time and space complexity
The program prints one character for each position in the pattern, so for n rows it runs in O(nΒ²) time. It only needs a few loop variables, so the extra memory is O(1).
Frequently asked questions
How do I line up the 5s in one column?
Print n β i spaces before each row. The rows then end in the same column, and every digit sits under the same digit in the row above.
What is the difference from 1, 21, 321?
In the descending number triangle each row counts down to 1. Here each row counts up to n. Both grow by one number per row.
How do I let the user choose n?
Read n from the keyboard instead of fixing it in the code: scanf("%d", &n); in C, cin >> n; in C++, new Scanner(System.in).nextInt() in Java and int(input()) in Python.






