New: 213 pattern programs with tested code in C, C++, Java and Python Explore patterns

Rising Start Number Triangle (5, 45, 345)

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
  1. Rising Start Number Triangle output
  2. How the rising start number triangle works
  3. Rising Start Number Triangle in C
  4. Rising Start Number Triangle in C++
  5. Rising Start Number Triangle in Java
  6. Rising Start Number Triangle in Python
  7. Time and space complexity
  8. Frequently asked questions

Rising Start Number Triangle output

Output (n = 5):

5
45
345
2345
12345
Rising Start Number Triangle layout diagram, row by row (n = 5)
How each row of the rising start number triangle is built (n = 5). Blue cells are printed characters; grey dots are spaces.

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.

  1. Run the outer loop for i from 1 to n, one row per pass.
  2. Print i numbers (value n βˆ’ i + j).
  3. Move to the next line.

Key takeaways

  • Every row ends at n; only the starting number changes.
  • The starting number n βˆ’ i + 1 goes down by one each row.
  • The value n βˆ’ i + j rises by one per column.
  • Right-aligning the rows (with n βˆ’ i spaces) 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.

This tutorial was drafted with AI assistance. Spotted a mistake? Tell us and we fix it. Read our editorial policy.

Quick check: can you predict the output?

Answer from the code, then check. Every answer comes from the real output above.

Pattern 22 of 24 in Number Patterns

 

Still stuck? Ask AI to explain this code

Opens your favourite AI with this page, ready to explain every loop step by step.

Authored by

Ghanendra Yadav runs Pattern Programs from Bangalore, India. The site started in 2020 to help students practise loops and logic through pattern programs in C, C++, Java and Python. Every program published here is compiled and run before it goes live, and the output shown is the real output.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.