The alphabet diamond prints letters in the shape of a diamond: A on top, then ABC, ABCDE and ABCDEFG across the middle, and back down to A. Every row starts at A.
Quick answer: Each row i prints n β i spaces and then the first 2i β 1 letters of the alphabet. Run i from 1 to n for the top half and from n β 1 back down to 1 for the bottom half, so the widest row appears once.
This program is part of the String Patterns collection.
Table of contents8 sections
Alphabet Diamond Pattern output
Output (n = 4):
A ABC ABCDE ABCDEFG ABCDE ABC A

How the alphabet diamond pattern works
This is the star diamond with each star replaced by a letter. Because the letter depends only on the position in the row, 'A' + j β 1, every row spells the start of the alphabet. The widest row has 2n β 1 letters, so n = 4 reaches G. The same loop prints both halves; only the order of the rows changes.
- Run the outer loop for
ifrom1ton, one row per pass (upper half). - Print
n β ispaces. - Print
2 Γ i β 1letters (letter numberj). - Move to the next line.
- Run the outer loop for
ifromn β 1down to1, one row per pass (lower half). - Print
n β ispaces. - Print
2 Γ i β 1letters (letter numberj). - Move to the next line.
Key takeaways
- Every row prints the first
2i β 1letters, starting at A. - Leading spaces
n β icentre the rows, as in a star pyramid. - The lower half starts at
n β 1so the widest row is printed once. - The widest row ends at letter
2n β 1, sonmust be 13 or less.
Alphabet Diamond Pattern in C
#include <stdio.h>
int main(void) {
int n = 4;
// upper half
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int j = 1; j <= 2 * i - 1; j++)
printf("%c", 'A' + j - 1);
printf("\n");
}
// lower half
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int j = 1; j <= 2 * i - 1; j++)
printf("%c", 'A' + j - 1);
printf("\n");
}
return 0;
}Alphabet Diamond Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 4;
// upper half
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++)
cout << " ";
for (int j = 1; j <= 2 * i - 1; j++)
cout << char('A' + j - 1);
cout << endl;
}
// lower half
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++)
cout << " ";
for (int j = 1; j <= 2 * i - 1; j++)
cout << char('A' + j - 1);
cout << endl;
}
return 0;
}Alphabet Diamond Pattern in Java
public class AlphabetDiamond {
public static void main(String[] args) {
int n = 4;
// upper half
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++)
System.out.print(" ");
for (int j = 1; j <= 2 * i - 1; j++)
System.out.print((char) ('A' + j - 1));
System.out.println();
}
// lower half
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++)
System.out.print(" ");
for (int j = 1; j <= 2 * i - 1; j++)
System.out.print((char) ('A' + j - 1));
System.out.println();
}
}
}Alphabet Diamond Pattern in Python
n = 4
# upper half
for i in range(1, n + 1):
for j in range(1, n - i + 1):
print(" ", end="")
for j in range(1, 2 * i):
print(chr(ord('A') + j - 1), end="")
print()
# lower half
for i in range(n - 1, 0, -1):
for j in range(1, n - i + 1):
print(" ", end="")
for j in range(1, 2 * i):
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
How do I make each row a palindrome (A, ABA, ABCBA)?
Print letters 1 to i and then i β 1 back to 1, as in the alphabet palindrome pyramid, for both halves.
Why must n be 13 or less?
The widest row needs 2n β 1 letters. With n = 14 that is 27, one more than the alphabet has, and the last character is no longer a letter.
How do I add spaces between the letters?
Print each letter with a space after it and double the leading spaces. The diamond becomes wider but stays centred.






