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 %2c.
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 %2c).
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 %2c.
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 printf("\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 | printf(" "); when j > i |
| Letter cell | printf("%2c", 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 %2c 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, scanf row count, and explicit pad + letter loops. 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 %2c keeps columns aligned.
#include <stdio.h>
int main() {
int i, j;
char k = 'A';
for (i = 1; i <= 5; ++i) {
for (j = 5; j >= 1; --j) {
if (j > i) {
printf(" ");
} else {
printf("%2c", k++);
}
}
printf("\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 scanf and a letter-budget cap in real apps.
#include <stdio.h>
int main() {
int n, i, j;
char k = 'A';
printf("Enter number of rows (like 5): ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
for (j = n; j >= 1; --j) {
if (j > i) {
printf(" ");
} else {
printf("%2c", k++);
}
}
printf("\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 <stdio.h>
int main() {
int n = 5;
char k = 'A';
int i, s, L;
for (i = 1; i <= n; ++i) {
for (s = 0; s < n - i; ++s) {
printf(" ");
}
for (L = 0; L < i; ++L) {
printf("%2c", k++);
}
printf("\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 %2c, so each letter occupies 2 columns and lines up with the padding.
printf("\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 %2c 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 printf field widths like %2c.
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 %2c.
scanfAvoid 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 %2c 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.
scanfLetters or empty input leave n uninitialized.
→ Check scanf 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.
Unchecked scanf fails silently — check the return value.
Same loops with k = 'a'.
Try these variations to lock in the pattern.
k = 'A' each row once" " ↔ %2c).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.
scanf and cap the letter budgetk each row for this patternprintf("\n") inside the cell loopPrint the right-aligned sequential pyramid the beginner-friendly way.
Pad + continuous letters
DefinitionNever reset
Code" " & %2c
CodeEnds each scan
I/OO(n²) time
AnalysisEach slot is 2 columns wide. Padding uses " " and letters use %2c 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 letter pyramids.
12 people found this page helpful