The column-wise alphabet triangle fills the letters down the columns instead of across the rows: the first column reads A to F, the second G to K, the third L to O, and so on to U.
Quick answer: Column j holds n − j + 1 letters, so the columns before it use (j − 1)n − (j − 1)j/2 letters. The letter at row i, column j is therefore 'A' + i − 1 + (j − 1)n − (j − 1)j/2. One formula, no array.
This program is part of the String Patterns collection.
Table of contents8 sections
Column-Wise Alphabet Triangle output
Output (n = 6):
A B G C H L D I M P E J N Q S F K O R T U

How the column-wise alphabet triangle works
A console prints row by row, so the program has to know the letter in each cell without filling the columns first. The first column is just the row number. Each column to the right starts after all the letters of the columns before it, and those columns get one letter shorter each time: 6, 5, 4 and so on. Adding up that shrinking series gives the formula above. It is the alphabet twin of the column-wise Floyd’s triangle.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
iletters (letter numberi + (j − 1) × n − (j − 1) × j / 2). - Move to the next line.
Key takeaways
- The letters run down each column, not across each row.
- Column
jholdsn − j + 1letters. - The offset
(j − 1)n − (j − 1)j/2counts the letters in earlier columns. - Six rows use 21 letters, A to U.
Column-Wise Alphabet Triangle in C
#include <stdio.h>
int main(void) {
int n = 6;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
printf("%c ", 'A' + i + (j - 1) * n - (j - 1) * j / 2 - 1);
printf("\n");
}
return 0;
}Column-Wise Alphabet Triangle in C++
#include <iostream>
using namespace std;
int main() {
int n = 6;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
cout << char('A' + i + (j - 1) * n - (j - 1) * j / 2 - 1) << " ";
cout << endl;
}
return 0;
}Column-Wise Alphabet Triangle in Java
public class ColumnWiseAlphabetTriangle {
public static void main(String[] args) {
int n = 6;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print((char) ('A' + i + (j - 1) * n - (j - 1) * j / 2 - 1) + " ");
System.out.println();
}
}
}Column-Wise Alphabet Triangle in Python
n = 6
for i in range(1, n + 1):
for j in range(1, i + 1):
print(chr(ord('A') + i + (j - 1) * n - (j - 1) * j // 2 - 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 check the formula?
Take row 4, column 3 with n = 6: 4 + (3 − 1) × 6 − (3 − 1) × 3 / 2 = 4 + 12 − 3 = 13. The 13th letter is M, which is exactly what the output shows in that cell.
How many rows fit before the alphabet runs out?
Six rows use 21 letters. Seven rows would need 28, so stop at six or wrap around with % 26.
Can I use a two-dimensional array instead?
Yes: fill an array column by column with a counter, then print it row by row. The formula avoids the array.






