Sequential Alphabet Triangle in C++

What You’ll Learn
Each row is wider than the last, but letters stay in order across the whole shape: A, then B C, then D E F, up to K L M N O for five rows (with a space after each letter).
This differs from program 1 style triangles where each column is derived from j; here one counter k walks the alphabet continuously.
⭐ Pattern Output
For 5 rows (space after each letter):
A
B C
D E F
G H I J
K L M N OComplete C++ Program (Five Rows, ASCII Loops)
Loop variables i and j use ASCII 65–69 to control row width. The actual letters come from k, post-incremented in each cout.
#include <iostream>
using namespace std;
int main() {
int i, j;
int k = 65;
for (i = 65; i <= 69; i++) {
for (j = 65; j <= i; j++)
cout << (char) k++ << " ";
cout << "\n";
}
return 0;
}🧠 How It Works
k = 65 ('A')
Global position in the alphabet; it never resets between rows.
Outer i
Each value of i sets how many inner iterations run (1, 2, 3, 4, 5).
cout << (char) k++ << " "
Print the current letter, append a space, then advance k for the next cell.
cout << "\n"
After the inner loop finishes one row, start the next line.
Fifteen letters for five rows
O(n²) letters for n rows.
Variation — User Input + Character Literals
Same idea with readable 'A' bounds; last row ends at 'A' + rows - 1.
#include <iostream>
using namespace std;
int main() {
int rows;
int i, j;
char k = 'A';
cout << "Enter the number of rows: ";
cin >> rows;
for (i = 'A'; i <= 'A' + rows - 1; i++) {
for (j = 'A'; j <= i; j++)
cout << k++ << " ";
cout << "\n";
}
return 0;
}💡 Tips for Enhancement
Try These
- Fixed five rows with
char kandfor (i = 'A'; i <= 'E'; i++)— same output, clearer than65 - Omit the space in
coutif you want a tight triangle - Cap
rowssokdoes not pass'Z'
Avoid
- Resetting
kto'A'at every row (you would repeatA,BB, … instead of a run-through) - Incrementing
konly once per row (not enough letters on wider rows)
Key Takeaways
Inner loop count matches row width; k carries the alphabet forward.
k++ in the output runs once per printed character.
O(n²) output size for n rows.
ASCII and character-literal loops are interchangeable here.
❓ Frequently Asked Questions
k.cout uses the value of k first, then k advances for the next character.i <= 'A' + rows - 1, inner j from 'A' to i, same k++ body.Explore More C++ Alphabet Patterns!
One global k is the trick: row loops only decide how many times to print, not which letter.
This is the same structure as the C tutorial: printf("%c ", k++) and cout << (char) k++ << " " both advance the alphabet once per cell.
12 people found this page helpful
