Two Parts
Down then up
Descending prefix + ascending suffix each row.

Build fixed-width alphabet rows from two parts: a short descending prefix (row letter down to B) plus an ascending suffix (A up to a computed cap) — ABCDE, BABCD, CBABC, DCBAB, EDCBA. Compare Program 24 (palindrome split) and Program 26 (rotations). Includes a live preview, worked C examples, edge cases, and complexity.
Down then up
Descending prefix + ascending suffix each row.
j > 0
Prefix stops at B so A is not duplicated.
n − i
Ascending ends at 0..(n−i) to keep width n+1.
n+1
For A..E every row has exactly 5 letters.
End letter
Pick an end letter (A–F) and draw the rows.
Complexity
n rows × O(n) letters each.
Decreasing and increasing alphabet rows keep a constant width by trading a growing descending prefix against a shrinking ascending suffix that always starts at A.
In C you store the alphabet in an array, walk row index i from 0 to n, print i..1 descending, then print 0..(n-i) ascending.
It teaches composing a row from two opposite loops and choosing a cap so width stays fixed — a skill used in many constant-width letter grids.
i down to B.
A up to the cap.
Prefix skips index 0.
Always n+1 letters.
In short: for each i from 0 to n, print alpha[i]..alpha[1], then alpha[0]..alpha[n-i], then printf("\n").
Given an end letter (or fixed E), print n+1 fixed-width rows where a descending prefix grows and an ascending suffix shrinks.
// Five rows (end = E, width 5)
// ABCDE
// BABCD
// CBABC
// DCBAB
// EDCBA | Item | Type | Description |
|---|---|---|
end / n | char / int | End letter; n = end - 'A' (4 for E). Rows = n+1. |
| Printed output | text | Fixed-width rows of length n+1 with down+up letter parts. |
n = end - 'A'
for i from 0 to n:
for j from i down to 1: // descending prefix (skip A)
print letter[j]
for k from 0 to n - i: // ascending suffix
print letter[k]
print newline | Approach | Idea | Best for |
|---|---|---|
| Two inner loops | Prefix i..1 then suffix 0..(n-i) | Matching this classic sample |
| Build then reverse-slice | Compose a string per row | When you prefer string ops over char indexes |
| Goal | Pattern |
|---|---|
| Alphabet + n | char alpha[] = "ABCDEFG..."; int n = 4; |
| Rows | for (int i = 0; i <= n; i++) |
| Descending prefix | for (int j = i; j > 0; j--) printf("%c", alpha[j]); |
| Ascending suffix | for (int k = 0; k <= n - i; k++) printf("%c", alpha[k]); |
| V-shaped next | See Program 31 |
Four roles that keep every row the same width.
prefixDescending letters; skips A
suffixAscending fill from A
capShrinks as the prefix grows
breakEnds the row after both parts
Reach for this when teaching constant-width rows built from opposite letter directions.
Switch from layered floors to fixed-width row composition.
Practice caps that keep every row the same length.
Skip A on the left so the ascending part owns the join.
Work with 0-based alphabet indexes instead of raw chars.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one descending prefix (skip A) plus a capped ascending suffix is the cleanest way to keep fixed-width down/up alphabet rows.
Choose an end letter from A to F and draw the decreasing/increasing alphabet rows in the browser.
Three complete C programs — fixed A–E, scanf end letter, and a print_row helper. Click View Output to reveal sample console results.
Print five fixed-width rows from ABCDE down to EDCBA.
Matches the reference logic: print alpha[i]…alpha[1], then alpha[0]…alpha[4 - i].
#include <stdio.h>
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, j, k;
for (i = 0; i <= 4; i++) {
for (j = i; j > 0; j--)
printf("%c", alpha[j]);
for (k = 0; k <= 4 - i; k++)
printf("%c", alpha[k]);
printf("\n");
}
return 0;
} When i = 2, the prefix prints C B and the suffix prints A B C → CBABC. Prefix length + suffix length is always 5.
Let the user pick the end letter (like E).
Works for A..end with the same two-part row. Check scanf and validate a single A–Z character in real apps.
#include <stdio.h>
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char end;
int n, i, j, k;
printf("Enter end letter (like E): ");
scanf(" %c", &end);
n = end - 'A';
for (i = 0; i <= n; i++) {
for (j = i; j > 0; j--)
printf("%c", alpha[j]);
for (k = 0; k <= n - i; k++)
printf("%c", alpha[k]);
printf("\n");
}
return 0;
} n = end - 'A' scales both loops. For end = C, width is 3 and you get three rows.
Same shape with a shared print_row helper.
Often clearer: one function owns both parts so main only walks row indexes.
#include <stdio.h>
void print_row(char alpha[], int n, int i) {
int j, k;
for (j = i; j > 0; j--)
printf("%c", alpha[j]);
for (k = 0; k <= n - i; k++)
printf("%c", alpha[k]);
printf("\n");
}
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n = 4;
int i;
for (i = 0; i <= n; i++)
print_row(alpha, n, i);
return 0;
} print_row owns the prefix/suffix pair. The outer loop only decides which row index i to print.
When i = 0 start at A; when i = 4 start at E. Outer loop runs i from 0 to n.
Loop j from i down to 1. This prints the row letter down to B and avoids duplicating A at the join.
Print A through indices 0..(n - i) so total length is always n + 1 (5 for A..E).
Prefix length is i; suffix length is n - i + 1. Together they always equal n + 1.
Left side grows while the right side shrinks — O(n²) time for n letters.
Trace each row index, both parts, and the joined 5-letter line.
i | Prefix (i..1) | Suffix (0..4-i) | Printed row |
|---|---|---|---|
0 | (empty) | ABCDE | ABCDE |
1 | B | ABCD | BABCD |
2 | CB | ABC | CBABC |
3 | DCB | AB | DCBAB |
4 | EDCB | A | EDCBA |
Width is always 4 + 1 = 5. The last row is a full reverse run ending at a single A.
Where these decreasing/increasing alphabet rows show up beyond the homework prompt.
Clearest demo of trading prefix growth against suffix shrink.
Example: count letters each row and confirm width stays 5.
Skip A on the left so the ascending part owns the join.
Example: change j > 0 to j >= 0 and see a double A.
Practice n = end - 'A' with an alphabet array.
Example: scale from E to H without rewriting loops.
Factor both parts into print_row (Example 3).
Example: reuse print_row for spaced output later.
Fixed width × n rows makes O(n²) easy to see.
Example: 5 rows × 5 letters = 25 prints.
Next draws a V using diagonal conditions instead of full rows.
Example: continue to Program 31.
Pro Tip: say “prefix i..B, suffix A..(n-i), width always n+1” before coding — that story prevents a duplicated A at the join.
Why this pattern earns a spot after the reverse-centered pyramid.
A wrong cap or double A shows up immediately in row width.
Down then up is easy to explain and debug.
Change n and every row stays the new width.
print_row keeps main short and readable.
Pro Tip: learn the inline loops first; extract print_row once the width budget feels automatic.
Small habits that keep decreasing/increasing rows clean.
Use j > 0 so A is printed only by the suffix.
That bound is what keeps width constant.
Use n = end - 'A' so scaling stays automatic.
scanfRequire a single A–Z character; use toupper if needed.
Duplicated prefix/suffix loops are a strong helper signal.
Pro Tip: if a middle row shows ...AA..., the prefix almost certainly included index 0.
Mistakes that commonly break decreasing/increasing alphabet rows.
Duplicates A at the join.
→ Keep for (j = i; j > 0; j--).
Using n or n - i - 1 breaks constant width.
→ Loop k from 0 to n - i inclusive.
Char math can walk past the alphabet.
→ Validate a single A–Z letter.
scanfEmpty or multi-character input leaves end unused or only takes the first char.
→ Check scanf’s return value and require a single A–Z letter.
Ascending first then descending produces a different pattern.
→ Keep prefix descending, then suffix ascending.
Check these inputs before calling the solution done.
Output is just A (prefix empty).
5 rows × width 5 through EDCBA.
ABC / BAB / CBA (Example 2).
Convert lowercase with toupper from <ctype.h> if needed.
Check scanf’s return value before using end.
Print alpha[j] + " " without changing bounds.
Try these variations to lock in the pattern.
j >= 0 oncej > 0n + 1 (5 for A..E).Quick Takeaway: print i..B descending, then A..(n-i) ascending, skip duplicating A, then break the line.
| Program | Time | Extra space |
|---|---|---|
| Inline / input (Examples 1–2) | O(n²) | O(1) (plus alphabet source) |
| Helper function (Example 3) | O(n²) | O(1) |
For n+1 letters (indexes 0..n) there are n+1 rows and each row prints n+1 characters, so total work is O(n²).
Decreasing and increasing alphabet rows are a small nested-loop exercise with lasting payoff: opposite letter directions, a join that skips a duplicate A, and a cap that keeps width fixed. Master the classic ABCDE…EDCBA sample, then try user input and the helper rewrite.
Practice the three examples above, then continue to Program 31’s V-shaped alphabet pattern.
Prefix i..1, suffix 0..(n-i), skip duplicating A, then break the line.
j > 0k <= n - in from the end letterprintf("\n") inside either part loopPrint decreasing & increasing alphabet rows the beginner-friendly way.
Down then up
Definitioni..1 (skip A)
Code0..(n-i)
CodeAlways n+1
ShapeO(n²) time
AnalysisFor each row i (A..E), print a descending prefix from i down to B (skip A), then print an ascending suffix from A up to A + E - i. That cap keeps row width constant at E - A + 1.
Next up: V-shaped alphabet patterns that print letters only on two diagonals meeting at the bottom vertex.
12 people found this page helpful