Shape Rule
Palindrome rows
Each row reads the same forward and backward.

Each row is a palindrome: go up from A to the row’s peak letter, then come back down without repeating the peak — A, ABA, ABCBA, ABCDCBA, ABCDEDCBA. Compare Program 1 (left half only) and Program 16 (centered consecutive letters). Includes a live preview, worked C examples, edge cases, and complexity.
Palindrome rows
Each row reads the same forward and backward.
Row peak
Row r peaks at letter 'A' + r (0-based) or alpha[i].
A..peak
First inner loop prints up through the peak letter.
peak-1..A
Start at peak - 1 so the center is not duplicated.
1–10 rows
Pick a height and draw the palindrome pyramid instantly.
Complexity
Odd row lengths sum to n² characters.
A palindromic alphabet pyramid grows one peak letter per row and mirrors the left half so the full line reads the same both ways — without printing the peak twice.
In C you usually solve it with three loops: an outer row loop, a forward letter loop, and a reverse letter loop that starts at peak - 1.
It teaches the classic “up then down, skip the center” mirror trick used in many palindrome and diamond patterns.
Row r peaks at the r-th letter.
Print A through the peak.
Mirror from peak - 1 to A.
Rows have 1, 3, 5, … letters.
In short: for each peak, print A..peak, then (peak-1)..A, then printf("\n") — never start the mirror at peak.
Given a row count n (or fixed A–E), print a left-aligned pyramid where each row is an alphabet palindrome.
// Five rows (no spaces between letters)
// A
// ABA
// ABCBA
// ABCDCBA
// ABCDEDCBA | Item | Type | Description |
|---|---|---|
n / rows | int | Number of pyramid rows (1–26 for A–Z). |
| Printed output | text | Palindrome rows with odd lengths 1, 3, 5, … |
for each row r (0..n-1):
peak = 'A' + r
print 'A'..peak
print (peak-1)..'A'
print newline | Approach | Idea | Best for |
|---|---|---|
| Index + char array | alpha[j] / alpha[k] | Matching this classic sample |
Direct char loops | Walk letters without an array | Clearer user-input versions |
| Goal | Pattern |
|---|---|
| Rows / peaks | for (i = 'A'; i <= endChar; ++i) |
| Forward half | for (j = 'A'; j <= i; ++j) printf("%c", j); |
| Mirror half | for (k = i - 1; k >= 'A'; --k) printf("%c", k); |
| Avoid double peak | Start mirror at i - 1, not i |
| End the row | printf("\n"); |
| Left half only | See Program 1 |
Same row — three different jobs.
upBuilds the left half including the center
downMirrors without repeating the peak
onceAppears only from the forward loop
breakEnds the row after both halves
Reach for this when teaching mirror loops and palindrome rows.
You already print A..peak; now add the mirror half.
Practice skipping the center so mirrors stay clean.
Same up/down idea appears in number and star diamonds.
Next you add a spacing gap between mirrored ramps.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one careful start index (peak - 1) turns a left triangle into a full palindrome.
Choose between 1 and 10 rows and draw the palindromic alphabet pyramid in the browser.
Three complete C programs — fixed A–E, scanf row count, and a centered variant with leading spaces. Click View Output to reveal sample console results.
Print five palindrome rows with nested char loops.
Print the forward part A..i, then print back from i-1..A.
#include <stdio.h>
int main() {
int i, j, k;
for (i = 'A'; i <= 'E'; ++i) {
for (j = 'A'; j <= i; ++j) {
printf("%c", j);
}
for (k = i - 1; k >= 'A'; --k) {
printf("%c", k);
}
printf("\n");
}
return 0;
} When i = 'C', the forward loop prints ABC and the reverse loop starts at 'B' → BA, giving ABCBA. Starting at i instead of i - 1 would wrongly print ABCCBA.
Let the user choose how many rows to print.
Uses character bounds and endChar = 'A' + rows - 1. Check scanf in real apps.
#include <stdio.h>
int main() {
int rows;
int i, j, k;
char endChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
endChar = (char)('A' + rows - 1);
for (i = 'A'; i <= endChar; ++i) {
for (j = 'A'; j <= i; ++j) {
printf("%c", j);
}
for (k = i - 1; k >= 'A'; --k) {
printf("%c", k);
}
printf("\n");
}
return 0;
} Outer i walks from 'A' to endChar. Cap rows at 26 so peaks stay within A–Z.
Same palindromes, centered with leading spaces.
Add leading spaces so shorter rows sit under the widest row (same idea as Program 16).
#include <stdio.h>
int main() {
int n = 5;
int r, s;
char peak, ch;
for (r = 0; r < n; ++r) {
peak = (char)('A' + r);
for (s = 0; s < n - r - 1; ++s) {
printf(" ");
}
for (ch = 'A'; ch <= peak; ++ch) {
printf("%c", ch);
}
for (ch = (char)(peak - 1); ch >= 'A'; --ch) {
printf("%c", ch);
}
printf("\n");
}
return 0;
} Pad with n - r - 1 spaces, then print the same up/down palindrome as before. The letter logic does not change — only alignment does.
#include <stdio.h> brings in printf / scanf. Choose a peak range such as 'A'..'E'.
Row i ends at alpha[i] or (char)('A' + r).
Print A..peak, then (peak-1)..A so the center appears once.
printf("\n") ends the row so the next peak starts fresh.
Odd lengths sum to n² — O(n²) time, O(1) extra memory.
Trace each row’s peak and both halves.
Row i | Peak | Forward | Mirror | Printed row |
|---|---|---|---|---|
0 | A | A | (empty) | A |
1 | B | AB | A | ABA |
2 | C | ABC | BA | ABCBA |
3 | D | ABCD | CBA | ABCDCBA |
4 | E | ABCDE | DCBA | ABCDEDCBA |
Lengths: 1 + 3 + 5 + 7 + 9 = 25 = 5².
Where this palindrome pyramid (and its mirror trick) shows up beyond the homework prompt.
Clearest alphabet demo of up-then-down without doubling the center.
Example: start mirror at peak once and see the double letter.
Same forward half; this pattern completes the palindrome.
Example: print left-only vs full mirror side by side.
Same loops work with digits instead of letters.
Example: print 1, 121, 12321, …
Add pads (Example 3) after the letter logic is solid.
Example: compare left-aligned vs centered output.
Odd sums make the n² total easy to see.
Example: 5 rows print 25 letters total.
Practice limiting input so peaks stay in A–Z.
Example: reject n > 26 or clamp it.
Pro Tip: say “up through the peak, then down from peak minus one” before coding — that story prevents doubled centers.
Why this pattern earns a spot after left-half alphabet triangles.
A doubled peak shows up immediately as a non-palindrome.
The same peak - 1 idea appears in many diamond labs.
Char arrays or direct char loops teach the same shape.
Streaming output needs no storage beyond loop variables.
Pro Tip: get the left-aligned palindrome right first; add centering pads only after the letters look correct.
Small habits that keep palindrome-pyramid code clean.
That single off-by-one is the whole palindrome trick.
0-based rows with 'A' + r avoid mixing 1-based peaks by accident.
scanfAvoid crashes when the user types letters instead of a number.
Beyond Z you need a wrap/stop policy.
Trace ABC + BA on paper before coding larger n.
Pro Tip: if you see doubled centers like ABCCBA, you almost certainly started the mirror at the peak.
Mistakes that commonly break palindromic alphabet pyramids.
Duplicates the center (ABCCBA instead of ABCBA).
→ Begin the reverse loop at peak - 1.
Wrong peak letter on every row.
→ Stick to one scheme: r from 0 with 'A' + r.
Large n walks past the alphabet.
→ Cap input at 26 or define a wrap policy.
scanfLetters or empty input leave rows uninitializeduninitialized rows.
→ Check scanf’s return value and re-prompt on failure.
printf("\n") Inside a Half LoopBreaks the row into one character per line.
→ Call printf("\n") only after both halves finish.
Check these inputs before calling the solution done.
Output is just A; mirror loop does not run.
Through ABCDEDCBA.
Stops at ABCDCBA (Example 2).
Reject, clamp, or wrap — decide explicitly.
Unchecked scanf fails silently — check the return value.
Same loops with 'a' as the base.
Try these variations to lock in the pattern.
ch + " " in both halves2r - 1 (1-based r); totals over n rows equal n².char loops are interchangeable here.Quick Takeaway: print up through the peak, mirror from peak minus one, then break the line — that is the whole pyramid.
| Program | Time | Extra space |
|---|---|---|
| Fixed / input (Examples 1–2) | O(n²) | O(1) |
| Centered (Example 3) | O(n²) | O(1) |
Row r (1-based) prints 2r - 1 letters; summing over n rows gives n² character writes.
The palindromic alphabet pyramid is a small nested-loop exercise with lasting payoff: grow a peak, print forward, then mirror from peak - 1. Master the classic A–E sample, then try user input and optional centering.
Practice the three examples above, then continue to Program 19’s mirrored alphabet with a shrinking space gap.
Print A..peak, then (peak-1)..A, and break only after both halves finish.
peak - 1scanf for inputprintf("\n") inside a letter loopPrint the palindromic alphabet pyramid the beginner-friendly way.
Up then mirror down
DefinitionA..peak
Codepeak-1..A
CodeEnds each row
I/OO(n²) time
AnalysisEach row prints A up to the row peak, then prints back down starting from peak - 1 so the middle letter appears only once. Row length is 2r - 1 for row r, so the total characters over n rows is n².
Next up: mirrored alphabet rows with a shrinking space gap in the middle.
12 people found this page helpful