The alphabet pyramid prints A on the top row, A B on the second and so on, with each row centred. It is the number pyramid with letters in place of digits.
Quick answer: Row i prints n − i spaces and then the first i letters, each followed by a space. The letter at position j is 'A' + j − 1: adding a number to a character moves that many places along the alphabet.
This program is part of the Pyramid Patterns collection.
Table of contents8 sections
Alphabet Pyramid Pattern output
Output (n = 5):
A A B A B C A B C D A B C D E

Same shape, other characters: the Centred Repeated Number Pyramid, Continuous Alphabet 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 alphabet pyramid pattern works
Characters are stored as numbers, so 'A' + 2 is 'C'. That makes letter patterns the same as number patterns with an offset: wherever a number pattern prints j, a letter pattern prints 'A' + j − 1. The spacing works as in any centred pyramid: each letter and its space take two characters, so one less leading space per row keeps the rows centred.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
n − ispaces. - Print
iletters (letter numberj). - Move to the next line.
Key takeaways
- A letter is a number:
'A' + kis the letterkplaces after A. - Any number pattern becomes a letter pattern by printing
'A' + value − 1. - In Java and C++ cast the result back to
char; in Python usechr(65 + k). - With 26 letters,
ncan go up to 26 before you run out of alphabet.
Alphabet Pyramid 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 <= i; j++)
printf("%c ", 'A' + j - 1);
printf("\n");
}
return 0;
}Alphabet Pyramid 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 <= i; j++)
cout << char('A' + j - 1) << " ";
cout << endl;
}
return 0;
}Alphabet Pyramid Pattern in Java
public class AlphabetPyramid {
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' + j - 1) + " ");
System.out.println();
}
}
}Alphabet Pyramid 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, i + 1):
print(chr(ord('A') + 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
Why does Java need a cast to char?
In Java, 'A' + 2 is an int (67). Printing it shows 67, not C. Casting with (char) turns it back into the letter.
How do I print lowercase letters?
Start from 'a' instead of 'A'. Everything else stays the same.
What happens if n is larger than 26?
The letters run past Z into other characters: 'A' + 26 is the bracket [. Wrap around with (j − 1) % 26 if you need more than 26 positions.
How do I make every row repeat its own letter (A, B B, C C C)?
Print 'A' + i − 1 instead of 'A' + j − 1. The letter then depends on the row, not the position.






