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

Number Rhombus Pattern

The number rhombus pattern prints 12345 on every row and moves each row one space to the left, so the block of numbers leans like a rhombus, the number version of the rhombus star pattern.

Quick answer: Every row prints the same 1 to n. Only the indent changes: row i starts with n βˆ’ i spaces, so the first row is pushed furthest right and the last row starts at the left edge.

This program is part of the Number Patterns collection.

Table of contents8 sections
  1. Output
  2. How the number rhombus pattern works
  3. Program in C
  4. Program in C++
  5. Program in Java
  6. Program in Python
  7. Time and space complexity
  8. Frequently asked questions

Number Rhombus Pattern output

Output (n = 5):

    12345
   12345
  12345
 12345
12345
Number Rhombus Pattern layout diagram, row by row (n = 5)
How each row of the number rhombus pattern is built (n = 5). Blue cells are printed characters; grey dots are spaces.

Same shape, other characters: the Rhombus Star Pattern program draws 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 number rhombus pattern works

A rhombus is a square that has been pushed sideways. The rows are identical, so the inner loop that prints 1 to n never changes; the slant comes entirely from the spaces in front. Because the indent drops by exactly one each row, every column of digits forms a straight diagonal line.

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

Key takeaways

  • All rows are the same: 1 to n.
  • The leading spaces n βˆ’ i create the slant.
  • Each digit forms a diagonal line down to the left.
  • Using i βˆ’ 1 spaces instead makes the rhombus lean the other way.

Number Rhombus Pattern in C

#include <stdio.h>

int main(void) {
    int n = 5;

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

Number Rhombus Pattern in C++

#include <iostream>
using namespace std;

int main() {
    int n = 5;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - i; j++)
            cout << " ";
        for (int j = 1; j <= n; j++)
            cout << j;
        cout << endl;
    }
    return 0;
}

Number Rhombus Pattern in Java

public class NumberRhombus {
    public static void main(String[] args) {
        int n = 5;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i; j++)
                System.out.print(" ");
            for (int j = 1; j <= n; j++)
                System.out.print(j);
            System.out.println();
        }
    }
}

Number Rhombus Pattern in Python

n = 5

for i in range(1, n + 1):
    for j in range(1, n - i + 1):
        print(" ", end="")
    for j in range(1, n + 1):
        print(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 make it lean to the right?

Print i βˆ’ 1 spaces instead of n βˆ’ i. The first row then starts at the left edge and each row moves one step right, like the mirrored rhombus.

Can every row repeat its row number instead?

Yes. Print i instead of j: 11111, 22222 and so on, still slanted.

Why does every column form a diagonal?

Each row is the same five digits, and each row starts one column further left. So the 1 of row 2 sits one place left of the 1 of row 1, and the same goes for every digit. Following one digit down the rows traces a straight line down to the left.

How do I make a hollow number rhombus?

Print j only when i == 1, i == n, j == 1 or j == n, and a space otherwise, keeping the same indent.

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 24 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.