Shape Rule
Odd widths, centered
Rows print 1, 3, 5… letters under a fixed bottom width.

Print a centered pyramid: one letter on the first row, then 3 letters, then 5 letters, with leading spaces so it looks aligned. Letters flow continuously via one counter: A, then B C D, then E F G H I. Compare Program 14 (odd widths, no centering) and Program 13 (sequential, left-aligned). Includes a live preview, worked C examples, edge cases, and complexity.
Odd widths, centered
Rows print 1, 3, 5… letters under a fixed bottom width.
Step by 2
for (int i = 1; i <= width; i += 2) picks each odd row width.
Pad then letters
When j > i print a space; otherwise print the next letter.
Never reset
One k (or index) walks A, B, C… across the whole pyramid.
1–5 rows
Pick a pyramid height and draw it instantly in the browser.
Complexity
Each row scans O(width) columns; overall work is O(r²).
A centered alphabet pyramid grows by two letters on each new line and pads the left with spaces so shorter rows sit under the widest row. Letters stay consecutive across the whole shape — they do not restart at A each row.
In C you usually solve it with nested loops: the outer loop steps odd widths, the inner loop scans a fixed bottom width printing spaces or the next letter, then printf("\n") ends the row.
It combines three beginner skills at once: odd-width growth, leading-space centering, and a continuous letter counter — the same toolkit used for many pyramids and diamonds.
Rows print 1, 3, 5, … letters.
Pad left so short rows stay centered.
One counter never resets between rows.
Inner loop always walks the bottom width.
In short: scan each odd width with pads where j > i, print consecutive letters with printf("%c ", k++), then printf("\n").
Given an odd bottom width (like 5) or a row count, print a centered pyramid of consecutive alphabet letters with leading spaces.
// Three rows (conceptual shape; spaces matter)
// A
// B C D
// E F G H I | Item | Type | Description |
|---|---|---|
width / rows | int | Odd bottom width (1, 3, 5, …) or number of pyramid rows. Width = 2*rows - 1. |
| Printed output | text | Centered odd-width rows of consecutive letters with leading spaces. |
k = 'A' (or index 0 into A..Z)
for i in 1, 3, 5, ... width:
for j from width down to 1:
if j > i: print space
else: print next letter (+ optional trailing space)
print newline | Approach | Idea | Best for |
|---|---|---|
| Fixed-width scan | Inner loop always walks width columns | Matching this classic sample |
| Explicit pad + letters | Print (width-i) spaces, then i letters | Clearer reading / teaching rewrite |
| Goal | Pattern |
|---|---|
| Odd row widths | for (i = 1; i <= width; i += 2) or ASCII 65..69 |
| Scan columns | for (j = width; j >= 1; --j) |
| Leading pad | if (j > i) printf(" "); |
| Next letter | printf("%c ", k++); |
| End the row | printf("\n"); |
| No centering | See Program 14 |
Same pyramid — different roles on each inner-loop pass.
padPrinted while j > i to center the row
fillPrinted when inside the current odd width
nextAdvances the continuous alphabet stream
breakEnds the row after the full column scan
Reach for this pyramid when teaching centering and continuous fills together.
Keep odd widths; add leading spaces for a centered look.
Practice left padding the same way star pyramids do.
Reuse the running-letter idea from Program 13 with centering.
Once centering clicks, inverted and full diamond shapes follow.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in odd-width growth, padding, and continuous fill at the same time.
Choose a pyramid height between 1 and 5 rows (bottom width = 2×rows−1) and draw it in the browser.
Three complete C programs — fixed width 5, odd-width input, and an explicit pad-then-letters rewrite. Click View Output to reveal sample console results.
Print a three-row pyramid with a fixed-width scan.
5Hard-coded bounds — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int i, j;
int k = 65;
for (i = 65; i <= 69; i += 2) {
for (j = 69; j >= 65; --j) {
if (j > i) {
printf(" ");
} else {
printf("%c ", k++);
}
}
printf("\n");
}
return 0;
} When i = 65 ('A'), four columns print spaces and one prints A. When i = 67 ('C'), two spaces then B C D. When i = 69 ('E'), the full width prints E F G H I.
Let the user choose an odd bottom width.
Read the bottom width as an odd number (like 5 or 7). Check scanf and odd validation in real apps.
#include <stdio.h>
int main() {
int width, i, j;
char k = 'A';
printf("Enter the bottom width (odd number): ");
scanf("%d", &width);
for (i = 1; i <= width; i += 2) {
for (j = width; j >= 1; --j) {
if (j > i) {
printf(" ");
} else {
printf("%c ", k++);
}
}
printf("\n");
}
return 0;
} Same centering scan as Example 1; only the outer/inner bounds follow width. Require an odd width so rows stay 1, 3, 5, … under a matching bottom line.
Same pyramid with separate pad and letter loops.
Often clearer to read: print leading spaces first, then the odd letter count.
#include <stdio.h>
int main() {
int rows = 3;
int width = 2 * rows - 1;
char k = 'A';
int row, letters, pad, s, L;
for (row = 1; row <= rows; ++row) {
letters = 2 * row - 1;
pad = width - letters;
for (s = 0; s < pad; ++s) {
printf(" ");
}
for (L = 0; L < letters; ++L) {
printf("%c", k);
if (L < letters - 1) {
printf(" ");
}
++k;
}
printf("\n");
}
return 0;
} Row r needs 2r-1 letters and width - letters leading spaces. Spaces between letters are separators only on the letter loop — same visual pyramid as the scan version.
#include <stdio.h> brings in printf / scanf. Create a running letter counter (k = 65 or char k = 'A').
i runs 1, 3, 5… — how many letters appear on the row.
Walk the bottom width. If j > i, print a space; else print the next letter and advance the counter.
printf("\n") ends the row so the next odd width starts fresh.
r rows scan O(width) columns each — O(r²) time, O(1) extra memory.
5Trace each outer value of i and see how many pads vs letters print.
i | Leading spaces | Letters | Printed row |
|---|---|---|---|
1 | 4 | A | ····A |
3 | 2 | B C D | ··B C D |
5 | 0 | E F G H I | E F G H I |
Total letters: 1 + 3 + 5 = 9 (A through I). Pads: 4 + 2 + 0 = 6.
Where this centered pyramid (and its padding idea) shows up beyond the homework prompt.
Clearest alphabet demo that leading spaces create a pyramid.
Example: remove pads and watch rows snap left.
Same odd widths — with or without centering.
Example: side-by-side left-aligned vs padded.
Keep a running counter across padded rows.
Example: reset k each row and compare to Program 1-style prefixes.
Same pad math works if you print * instead of letters.
Example: swap letter prints for printf("* ").
Fixed-width scans make O(r²) easy to count.
Example: 3 rows × 5 columns = 15 inner iterations.
Practice requiring odd widths before drawing.
Example: reject even width and re-prompt.
Pro Tip: say “pad first, then consecutive letters” before coding — that story prevents resetting k or forgetting spaces.
Why this pattern earns a spot after left-aligned odd-width triangles.
Missing pads or a reset counter show up immediately as a broken pyramid.
Same padding logic works for classic * pyramids.
Fixed-width scan or explicit pad/letter loops teach the same shape.
Streaming output needs no storage beyond counters.
Pro Tip: learn the classic scan version first; treat the explicit pad/letter rewrite as a clarity upgrade afterward.
Small habits that keep centered pyramid code clean.
Use 1, 3, 5, … so the pyramid stays symmetric under the bottom row.
Do not reset k each row if you want continuous letters.
scanfAvoid crashes when the user types letters instead of a number.
Width 9 uses 25 letters (A–Y); larger bottoms may pass Z.
Trace pads 4 / 2 / 0 on paper before coding larger demos.
Pro Tip: if every row starts with A, you almost certainly reset the letter counter inside the outer loop.
Mistakes that commonly break centered alphabet pyramids.
Rows shift left and no longer look like a pyramid.
→ Print pads while j > i (or print width - letters spaces first).
Each row starts at A again — that is a different pattern.
→ Keep k outside the outer loop.
Even widths break the 1, 3, 5… symmetry under the base.
→ Require an odd width (or derive width = 2*rows - 1).
scanfLetters or empty input leave width uninitialized.
→ Check scanf’s return value and re-prompt on failure.
Large odd widths need more than 26 letters.
→ Cap width so 1+3+…+width ≤ 26, or define wrap/stop policy.
Check these inputs before calling the solution done.
Output is just A on one line.
Three rows through I.
Reject or bump to next odd for a clean pyramid.
25 letters (A–Y) — last full A–Z-friendly odd width.
Unchecked scanf fails silently — check the return value.
Same loops work with k = 'a'.
Try these variations to lock in the pattern.
* instead of lettersk = 'A' each row oncewidth = 2*rows - 1 is a safe formula.Quick Takeaway: step odd widths, pad on the left, print consecutive letters, then break the line — that is the whole pyramid.
| Program | Time | Extra space |
|---|---|---|
| Fixed-width scan (Examples 1–2) | O(r²) | O(1) |
| Explicit pad + letters (Example 3) | O(r²) | O(1) |
With bottom width w = 2r-1, each of the r rows scans O(w) columns, so total work is O(r²).
The centered alphabet pyramid is a small nested-loop exercise with lasting payoff: odd-width growth, leading-space centering, and a continuous letter stream. Master the classic fixed-width scan, then optionally rewrite it as explicit pad + letter loops.
Practice the three examples above, then continue to Program 17’s reverse alphabet with a diagonal star.
Use an odd bottom width, pad while outside the current width, advance one letter counter across all rows, and break only after the scan.
width = 2*rows - 1)scanf and odd-width validationprintf("\n") inside the letter loopPrint the centered alphabet pyramid the beginner-friendly way.
Odd widths, centered pads
DefinitionWidths 1, 3, 5…
CodeContinuous letters
CodeEnds each scan
I/OO(r²) time
AnalysisThis pattern combines two ideas: odd-width rows (i += 2) and centering via padding spaces (like star pyramids). Letters flow continuously via one counter — A, then B C D, then E F G H I — while leading spaces keep each row aligned under the widest line.
Keep exploring alphabet and star mixes with nested loops.
12 people found this page helpful