The continuous number pyramid starts each row at the row number, climbs to its peak in the middle and comes back down: 1, then 232, then 34543. The peak goes up by two each row, so five rows reach 9.
Quick answer: Each row has three parts: n β i spaces, then i numbers counting up from i (i + j β 1), then i β 1 numbers counting back down (2i β 1 β j). On row 4 that is 4 5 6 7 followed by 6 5 4.
This program is part of the Pyramid Patterns collection.
Table of contents8 sections
Continuous Number Pyramid output
Output (n = 5):
1 232 34543 4567654 567898765

Same shape, other characters: the Alphabet Palindrome Pyramid, Full Pyramid Star Pattern and Palindrome Number Pyramid 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 continuous number pyramid works
Every row is a palindrome built around its middle number, 2i β 1. The rising half starts at i and needs i numbers to reach the middle. The falling half repeats those numbers in reverse, without the middle one, so it has i β 1 numbers and starts at 2i β 2. The spaces in front centre the row, exactly as in a star pyramid.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
n β ispaces. - Print
inumbers (valuei + j β 1). - Print
i β 1numbers (value2 Γ i β 1 β j). - Move to the next line.
Key takeaways
- Each row is a palindrome centred on
2i β 1. - The rising half has
inumbers, the falling halfi β 1. - Leading spaces
n β icentre the rows, as in the full pyramid. - Keep
nat 5 or less if numbers are printed without spaces, so the peak stays a single digit.
Continuous Number Pyramid 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 <= i; j++)
printf("%d", i + j - 1);
for (int j = 1; j <= i - 1; j++)
printf("%d", 2 * i - 1 - j);
printf("\n");
}
return 0;
}Continuous Number Pyramid 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 <= i; j++)
cout << i + j - 1;
for (int j = 1; j <= i - 1; j++)
cout << 2 * i - 1 - j;
cout << endl;
}
return 0;
}Continuous Number Pyramid in Java
public class ContinuousNumberPyramid {
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 <= i; j++)
System.out.print(i + j - 1);
for (int j = 1; j <= i - 1; j++)
System.out.print(2 * i - 1 - j);
System.out.println();
}
}
}Continuous Number Pyramid 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, i + 1):
print(i + j - 1, end="")
for j in range(1, i):
print(2 * i - 1 - 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 is it different from the palindrome number pyramid?
The palindrome number pyramid starts every row at 1 (1, 121, 12321). Here each row starts at its own row number (1, 232, 34543), so the numbers climb higher.
What goes wrong for n = 6?
Row 6 peaks at 11, a two-digit number, and the row becomes wider than the rows above. Print every number with a space or a fixed width and double the leading spaces to keep the shape.
How do I check the formulas quickly?
Test row 3: i + j β 1 gives 3, 4, 5 and 2i β 1 β j gives 4, 3. Put together that is 34543, which matches the output.






