The continuous alphabet pyramid keeps going through the alphabet instead of starting again on each row: A, then B C, then D E F. Five rows use the letters A to O.
Quick answer: Row i starts right after the i(i − 1)/2 letters used by the rows above, so the letter at position j is 'A' + i(i − 1)/2 + j − 1. Centre each row with n − i spaces and print each letter with a space after it.
This program is part of the Pyramid Patterns collection.
Table of contents8 sections
Continuous Alphabet Pyramid output
Output (n = 5):
A B C D E F G H I J K L M N O

Same shape, other characters: the Alphabet Pyramid Pattern, Centred Repeated Number Pyramid, Dollar ($) Pyramid, Number Pyramid Pattern and Pascal’s 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 continuous alphabet pyramid works
The letters follow the same order as the numbers in Floyd’s triangle: 1, 2 3, 4 5 6. Converting each Floyd number k to the letter 'A' + k − 1 gives this pattern. The triangle-number formula i(i − 1)/2 says how many letters came before row i, so no counter is needed.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
n − ispaces. - Print
iletters (letter numberi × (i − 1) / 2 + j). - Move to the next line.
Key takeaways
- The letters follow Floyd’s order: they never restart.
i(i − 1)/2counts the letters used by earlier rows.- Six rows would need 21 letters and seven rows 28, so stop at six to stay within A to Z.
- A running counter
ch++gives the same output.
Continuous Alphabet 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("%c ", 'A' + i * (i - 1) / 2 + j - 1);
printf("\n");
}
return 0;
}Continuous Alphabet 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 << char('A' + i * (i - 1) / 2 + j - 1) << " ";
cout << endl;
}
return 0;
}Continuous Alphabet Pyramid in Java
public class ContinuousAlphabetPyramid {
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((char) ('A' + i * (i - 1) / 2 + j - 1) + " ");
System.out.println();
}
}
}Continuous Alphabet 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(chr(ord('A') + i * (i - 1) // 2 + j - 1), 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 many rows fit in the alphabet?
Six rows use 21 letters (A to U). Seven rows would need 28, two more than the alphabet has, so keep n at 6 or less, or wrap around with % 26.
Can I use a counter instead of the formula?
Yes. Set ch = 'A' before the loops and print ch++ in the inner loop. It is shorter; the formula is handy when you need a single row.
How is it different from the alphabet pyramid?
The alphabet pyramid starts every row at A. This one carries on through the alphabet from row to row.






