Shape Rule
Right-aligned sequence
Growing rows of continuous letters sit on the right.

Print letters in a running sequence (A, then B C, then D E F…) while keeping the triangle right-aligned by printing empty 2-column cells first. View output in a monospace terminal because alignment relies on fixed-width cells. Compare Program 13 (sequential, left-aligned) and Program 20 (right-aligned reverse). Includes a live preview, worked C++ examples, edge cases, and complexity.
Right-aligned sequence
Growing rows of continuous letters sit on the right.
Never reset
k++ only when a letter prints — A…O across 5 rows.
Width 2
Pad with " "; print letters with setw(2).
j > i
Empty cells first, then letters for right alignment.
1–6 rows
Pick a height (max 6 keeps letters within A–U).
Complexity
n rows × n cells per fixed-width scan.
A right-aligned sequential alphabet pyramid prints a continuous stream of letters into a right-aligned triangle, using fixed-width cells so empty pads and letters share the same column size.
In C++ you solve it with nested loops, a running char counter, and matching pad/letter widths (" " vs setw(2) from <iomanip>).
It combines continuous counters, right alignment, and format-width printing — three skills that show up often in console layout labs.
k never resets between rows.
Empty cells print before letters.
" " matches setw(2).
Alignment needs a fixed-width font.
In short: for each row i, scan n cells — print " " while j > i, otherwise print the next letter with width 2, then call cout << "\n".
Given a row count n (or fixed 5), print a right-aligned pyramid of continuous alphabet letters in 2-column cells.
// Five rows (monospace; each cell is width 2)
// A
// B C
// D E F
// G H I J
// K L M N O | Item | Type | Description |
|---|---|---|
n | int | Number of rows. Letter count = n(n+1)/2 (15 for n=5). |
| Printed output | text | Right-aligned continuous letters in fixed-width cells. |
k = 'A'
for i in 1..n:
for j from n down to 1:
if j > i: print two spaces
else: print k with width 2; k++
print newline | Approach | Idea | Best for |
|---|---|---|
| Fixed-width scan | Pad or letter in each of n cells | Matching this classic sample |
| Explicit pad + letters | Print pads, then i letters via k++ | Clearer reading / teaching rewrite |
| Goal | Pattern |
|---|---|
| Counter | char k = 'A'; (outside outer loop) |
| Rows | for (int i = 1; i <= n; i++) |
| Scan cells | for (int j = n; j >= 1; j--) |
| Pad cell | cout << " "; when j > i |
| Letter cell | cout << setw(2) << k++; |
| Left-aligned sequence | See Program 13 |
Same fixed-width row — different roles on each cell.
pad2-column empty cell for right alignment
letterNext sequential letter in a width-2 field
streamContinues A, B, C… across every row
breakEnds the row after n cells
Reach for this when teaching continuous counters with fixed-width alignment.
Keep the running counter; add right alignment with width-2 cells.
Practice setw(2) matching pad width exactly.
Same right-align idea; sequential fill vs reverse suffixes.
Show why proportional fonts break column alignment.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: matching pad and letter widths turns a continuous alphabet stream into a clean right-aligned pyramid.
Choose between 1 and 6 rows and draw the right-aligned sequential pyramid in the browser (monospace cells).
Three complete C++ programs — fixed 5 rows, user-chosen row count, and an explicit pad-then-letters rewrite. Click View Output to reveal sample console results.
Print five right-aligned sequential rows with a running counter.
A single counter k increments only when a letter is printed, and setw(2) keeps columns aligned.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
char k = 'A';
for (int i = 1; i <= 5; i++) {
for (int j = 5; j >= 1; j--) {
if (j > i)
cout << " ";
else
cout << setw(2) << k++;
}
cout << "\n";
}
return 0;
} When i = 3, two cells print " " and three cells print D, E, F via k++. Because k is outside the outer loop, the next row continues at G.
Let the user choose how many rows to print.
Note: for large values, letters will go past Z. Check cin and a letter-budget cap in real apps.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n;
char k = 'A';
cout << "Enter number of rows (like 5): ";
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = n; j >= 1; j--) {
if (j > i)
cout << " ";
else
cout << setw(2) << k++;
}
cout << "\n";
}
return 0;
} Same pad/letter rules; only the shared width follows n. Letter count is n(n+1)/2 — cap so it stays ≤ 26 for A–Z only.
Same shape with separate pad and letter loops.
Often clearer to read: print n - i empty cells, then i sequential letters.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n = 5;
char k = 'A';
for (int i = 1; i <= n; i++) {
for (int s = 0; s < n - i; s++)
cout << " ";
for (int L = 0; L < i; L++)
cout << setw(2) << k++;
cout << "\n";
}
return 0;
} Pad count is n - i; letter count is i. Both still use width-2 cells so the visual pyramid matches the scan version.
k = 'A'A single running counter that never resets between rows.
The inner scan runs from n down to 1. When j > i we print two spaces to keep the same cell width as a letter.
We print letters using setw(2), so each letter occupies 2 columns and lines up with the padding.
cout << "\n" ends the row so the next row continues the same k.
Because k increments only when we print a letter, the alphabet continues across rows — O(n²) time.
Trace each row’s pads, letters, and the running counter range.
i | Pad cells | Letters | Printed row |
|---|---|---|---|
1 | 4 | A | ········A |
2 | 3 | B C | ······B C |
3 | 2 | D E F | ····D E F |
4 | 1 | G H I J | ··G H I J |
5 | 0 | K L M N O | K L M N O |
Total letters: 1+2+3+4+5 = 15 (A through O). Each cell is 2 columns wide.
Where this sequential right-aligned pyramid shows up beyond the homework prompt.
Clearest demo of a counter that never resets across rows.
Example: reset k once and compare to Program 1-style prefixes.
Same sequence — left-aligned vs right-aligned layout.
Example: print both for n = 5 side by side.
Match pad string length to setw(2) field width.
Example: try one-space pads and watch columns break.
Teach pad count separately from letter count (Example 3).
Example: compare scan vs pad+letters outputs.
Triangular letter counts make O(n²) easy to see.
Example: 5 rows print 15 letters (plus pad cells).
Practice capping n so n(n+1)/2 stays ≤ 26.
Example: n=7 needs 28 letters — past Z.
Pro Tip: say “empty cells first, then keep counting letters” before coding — that story prevents resetting k or mismatched widths.
Why this pattern earns a spot after left-aligned sequential triangles.
Mismatched pad width or a reset counter shows up immediately.
Fixed-width scan or explicit pad/letter loops teach the same shape.
A natural place to learn setw field widths.
Streaming output needs no storage beyond loop variables.
Pro Tip: learn the classic scan version first; treat the explicit pad/letter rewrite as a clarity upgrade afterward.
Small habits that keep right-aligned sequential pyramids clean.
Do not reset the counter each row if you want continuous letters.
Use two spaces when letters use setw(2).
cinAvoid crashes when the user types letters instead of a number.
Keep n(n+1)/2 ≤ 26 for A–Z-only output.
Proportional fonts make width-2 cells look misaligned.
Pro Tip: if every row starts with A, you almost certainly reset k inside the outer loop.
Mistakes that commonly break right-aligned sequential pyramids.
Each row starts at A again — that is a different pattern.
→ Keep k outside the outer loop.
Empty cells become narrower than setw(2) letter fields.
→ Print " " (two spaces) for each pad cell.
Columns look broken even when the code is correct.
→ View output in a monospace terminal/font.
cinLetters or empty input leave cin in a failed state.
→ Check cin.fail() and re-prompt on failure.
Large n needs more than 26 letters.
→ Cap n so n(n+1)/2 ≤ 26, or define wrap/stop policy.
Check these inputs before calling the solution done.
Output is just A (no pads).
15 letters through O.
Through F (Example 2).
Needs 28 letters — decide wrap/stop policy.
Check cin.fail() and re-prompt on failure.
Same loops with k = 'a'.
Try these variations to lock in the pattern.
k = 'A' each row once" " ↔ setw(2)).Quick Takeaway: pad empty width-2 cells first, print the next letters with matching width, keep counting across rows, then break the line.
| Program | Time | Extra space |
|---|---|---|
| Fixed-width scan (Examples 1–2) | O(n²) | O(1) |
| Explicit pad + letters (Example 3) | O(n²) | O(1) |
Each of n rows scans n cells (or pads + letters totaling n), so total work is O(n²).
The right-aligned sequential alphabet pyramid is a small nested-loop exercise with lasting payoff: a continuous letter counter, fixed-width cells, and leading empty cells for alignment. Master the classic A…O sample, then try user input and the explicit pad rewrite.
Practice the three examples above, then continue to Program 23’s right-aligned reverse alphabet pyramid.
Keep k outside, match pad and letter widths, print empty cells while j > i, then advance letters and break the line.
cin.fail() and cap the letter budgetk each row for this patterncout << "\n" inside the cell loopPrint the right-aligned sequential pyramid the beginner-friendly way.
Pad + continuous letters
DefinitionNever reset
Code" " & setw(2)
CodeEnds each scan
I/OO(n²) time
AnalysisEach slot is 2 columns wide. Padding uses " " and letters use setw(2) so columns line up in monospace output. The counter k never resets, so letters run continuously from A to O for 5 rows.
Next up: right-aligned reverse alphabet pyramids (E, E D, E D C, …).
12 people found this page helpful