The hollow alphabet triangle keeps only the edges of the alphabet triangle: the first column of A, the slanted side and the full bottom row ABCDE. Each letter stays in its own column.
Quick answer: Use the right-triangle loops: row i has i positions. Print the letter 'A' + j − 1 when j == 1, j == i or i == n, and a space for every other position.
This program is part of the String Patterns collection.
Table of contents8 sections
Hollow Alphabet Triangle output
Output (n = 5):
A AB A C A D ABCDE

Same shape, other characters: the Hollow Number Triangle and Hollow Right Triangle Star Pattern 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 hollow alphabet triangle works
The full triangle would print A, AB, ABC and so on. The hollow version uses the same positions but only fills the edges. Taking the letter from the column number means that a letter is always the same in a given column, so the slanted edge reads A, B, C, D, E from top to bottom.
- Run the outer loop for
ifrom1ton, one row per pass. - Go through
ipositions in the row. Print letters (letter numberj) wherej = 1 or j = i or i = n; print spaces everywhere else. - Move to the next line.
Key takeaways
- The edges are
j == 1,j == iand the last row. - The letter follows the column, so every column has one letter.
- The gap inside grows by one space each row.
- It matches the hollow number triangle with letters.
Hollow Alphabet 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++) {
if (j == 1 || j == i || i == n)
printf("%c", 'A' + j - 1);
else
printf(" ");
}
printf("\n");
}
return 0;
}Hollow Alphabet 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++) {
if (j == 1 || j == i || i == n)
cout << char('A' + j - 1);
else
cout << " ";
}
cout << endl;
}
return 0;
}Hollow Alphabet Triangle in Java
public class HollowAlphabetTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i || i == n)
System.out.print((char) ('A' + j - 1));
else
System.out.print(" ");
}
System.out.println();
}
}
}Hollow Alphabet Triangle in Python
n = 5
for i in range(1, n + 1):
for j in range(1, i + 1):
if j == 1 or j == i or i == n:
print(chr(ord('A') + j - 1), end="")
else:
print(" ", 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
Why is row 3 “A C” and not “A B”?
The C is in column 3. Since the letter comes from the column, position 3 is always C. To print “A B” instead, use a counter that only goes up when a letter is printed.
How do I fill the edges with the row letter?
Print 'A' + i − 1 instead. The edges then show A, BB, C C, D D, EEEEE.
How do I make a hollow alphabet pyramid?
Centre the rows and test the two ends of each row, as in the hollow alphabet pyramid.






