Decreasing & Increasing Alphabet Rows in C

Beginner
⏱️ 9 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

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.

Two Parts

Down then up

Descending prefix + ascending suffix each row.

Skip A Left

j > 0

Prefix stops at B so A is not duplicated.

Width Cap

n − i

Ascending ends at 0..(n−i) to keep width n+1.

Fixed Width

n+1

For A..E every row has exactly 5 letters.

Live Preview

End letter

Pick an end letter (A–F) and draw the rows.

O(n²)

Complexity

n rows × O(n) letters each.

Introduction

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.

Why it matters?

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.

Key Highlights

Prefix

i down to B.

Suffix

A up to the cap.

One A

Prefix skips index 0.

Fixed width

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").

📝 Problem & Approach

Given an end letter (or fixed E), print n+1 fixed-width rows where a descending prefix grows and an ascending suffix shrinks.

c
// Five rows (end = E, width 5)
// ABCDE
// BABCD
// CBABC
// DCBAB
// EDCBA

Inputs & Outputs

ItemTypeDescription
end / nchar / intEnd letter; n = end - 'A' (4 for E). Rows = n+1.
Printed outputtextFixed-width rows of length n+1 with down+up letter parts.

Minimal workflow

Pseudocode
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 comparison

ApproachIdeaBest for
Two inner loopsPrefix i..1 then suffix 0..(n-i)Matching this classic sample
Build then reverse-sliceCompose a string per rowWhen you prefer string ops over char indexes

⚡ Quick Reference

GoalPattern
Alphabet + nchar alpha[] = "ABCDEFG..."; int n = 4;
Rowsfor (int i = 0; i <= n; i++)
Descending prefixfor (int j = i; j > 0; j--) printf("%c", alpha[j]);
Ascending suffixfor (int k = 0; k <= n - i; k++) printf("%c", alpha[k]);
V-shaped nextSee Program 31

📋 Prefix vs Suffix vs Cap

Four roles that keep every row the same width.

j = i..1
prefix

Descending letters; skips A

k = 0..n-i
suffix

Ascending fill from A

n - i
cap

Shrinks as the prefix grows

printf("\n")
break

Ends the row after both parts

Context

When This Pattern Shows Up

Reach for this when teaching constant-width rows built from opposite letter directions.

  1. After diamond pyramids

    Switch from layered floors to fixed-width row composition.

  2. Width-budget drills

    Practice caps that keep every row the same length.

  3. Join-point practice

    Skip A on the left so the ascending part owns the join.

  4. Index mapping

    Work with 0-based alphabet indexes instead of raw chars.

  5. Not a UI layout tool

    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.

🔮 Live Preview

Choose an end letter from A to F and draw the decreasing/increasing alphabet rows in the browser.

Try E (classic sample) or C (smaller grid). Preview allows A–F.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed A–E, scanf end letter, and a print_row helper. Click View Output to reveal sample console results.

📚 Getting Started

Print five fixed-width rows from ABCDE down to EDCBA.

Example 1 — Fixed A–E

Matches the reference logic: print alpha[i]alpha[1], then alpha[0]alpha[4 - i].

c
#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;
}

How It Works

When i = 2, the prefix prints C B and the suffix prints A B CCBABC. Prefix length + suffix length is always 5.

📈 Practical Variant

Let the user pick the end letter (like E).

Example 2 — End Letter Input

Works for A..end with the same two-part row. Check scanf and validate a single A–Z character in real apps.

c
#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;
}

How It Works

n = end - 'A' scales both loops. For end = C, width is 3 and you get three rows.

⚡ Helper Style

Same shape with a shared print_row helper.

Example 3 — Helper Function

Often clearer: one function owns both parts so main only walks row indexes.

c
#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;
}

How It Works

print_row owns the prefix/suffix pair. The outer loop only decides which row index i to print.

🧠 How the Algorithm Prints Rows

1

Row index sets the starting letter

When i = 0 start at A; when i = 4 start at E. Outer loop runs i from 0 to n.

Rows
2

Descending prefix (skip A)

Loop j from i down to 1. This prints the row letter down to B and avoids duplicating A at the join.

Left
3

Ascending suffix fills remaining width

Print A through indices 0..(n - i) so total length is always n + 1 (5 for A..E).

Right
4

Width budget stays constant

Prefix length is i; suffix length is n - i + 1. Together they always equal n + 1.

Width
=

Same width every row

Left side grows while the right side shrinks — O(n²) time for n letters.

🔎 Worked Walkthrough — End = E (n = 4)

Trace each row index, both parts, and the joined 5-letter line.

iPrefix (i..1)Suffix (0..4-i)Printed row
0(empty)ABCDEABCDE
1BABCDBABCD
2CBABCCBABC
3DCBABDCBAB
4EDCBAEDCBA

Width is always 4 + 1 = 5. The last row is a full reverse run ending at a single A.

Use Cases

Where these decreasing/increasing alphabet rows show up beyond the homework prompt.

1. Width-Budget Labs

Clearest demo of trading prefix growth against suffix shrink.

Example: count letters each row and confirm width stays 5.

2. Join-Point Practice

Skip A on the left so the ascending part owns the join.

Example: change j > 0 to j >= 0 and see a double A.

3. Index Mapping

Practice n = end - 'A' with an alphabet array.

Example: scale from E to H without rewriting loops.

4. Helper Extraction

Factor both parts into print_row (Example 3).

Example: reuse print_row for spaced output later.

5. Complexity Intuition

Fixed width × n rows makes O(n²) easy to see.

Example: 5 rows × 5 letters = 25 prints.

6. Bridge to Program 31

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.

Advantages

Why this pattern earns a spot after the reverse-centered pyramid.

  1. 1. Instant Visual Feedback

    A wrong cap or double A shows up immediately in row width.

  2. 2. Clear Two-Part Story

    Down then up is easy to explain and debug.

  3. 3. Scales Cleanly

    Change n and every row stays the new width.

  4. 4. Helper-Friendly

    print_row keeps main short and readable.

Pro Tip: learn the inline loops first; extract print_row once the width budget feels automatic.

Usage Tips

Small habits that keep decreasing/increasing rows clean.

  1. 1. Stop the Prefix at 1

    Use j > 0 so A is printed only by the suffix.

  2. 2. Cap Suffix at n - i

    That bound is what keeps width constant.

  3. 3. Set n from the End Letter

    Use n = end - 'A' so scaling stays automatic.

  4. 4. Check scanf

    Require a single A–Z character; use toupper if needed.

  5. 5. Extract print_row When Ready

    Duplicated prefix/suffix loops are a strong helper signal.

Pro Tip: if a middle row shows ...AA..., the prefix almost certainly included index 0.

Common Pitfalls

Mistakes that commonly break decreasing/increasing alphabet rows.

  1. 1. Including A in the Prefix

    Duplicates A at the join.

    → Keep for (j = i; j > 0; j--).

  2. 2. Wrong Suffix Cap

    Using n or n - i - 1 breaks constant width.

    → Loop k from 0 to n - i inclusive.

  3. 3. End Letter Past Z

    Char math can walk past the alphabet.

    → Validate a single A–Z letter.

  4. 4. Unchecked scanf

    Empty 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.

  5. 5. Swapping Loop Directions

    Ascending first then descending produces a different pattern.

    → Keep prefix descending, then suffix ascending.

Edge Cases

Check these inputs before calling the solution done.

end = A

Single letter

Output is just A (prefix empty).

end = E

Classic sample

5 rows × width 5 through EDCBA.

end = C

Smaller grid

ABC / BAB / CBA (Example 2).

Lowercase

Case mismatch

Convert lowercase with toupper from <ctype.h> if needed.

Bad input

Empty / multi-char

Check scanf’s return value before using end.

Spaced

Readability

Print alpha[j] + " " without changing bounds.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Duplicate A on purpose

  • Change the prefix to j >= 0 once
  • Confirm why the sample uses j > 0

2. Extract print_row

  • Use a helper (Example 3)
  • Keep both parts inside it

3. Scale to H

  • Set end = H and recompute n
  • Check every row has width 8

4. Continue to Program 31

Notes

  • Two parts. Descending prefix then ascending suffix keep fixed width.
  • Stop the prefix at index 1 so A appears once at the join.
  • Row width is always n + 1 (5 for A..E).
  • Program 31 switches to a V-shaped diagonal letter pattern.

Quick Takeaway: print i..B descending, then A..(n-i) ascending, skip duplicating A, then break the line.

⏱️ Time and Space Complexity

ProgramTimeExtra 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²).

Wrap Up

🎉 Conclusion

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.

💡 Best Practices

✅ Do

  • Stop the prefix at j > 0
  • Cap the suffix at k <= n - i
  • Derive n from the end letter
  • Validate a single A–Z end letter for input variants
  • State O(n²) when asked about complexity

❌ Don’t

  • Include A in the descending prefix
  • Hard-code n without updating the alphabet source
  • Change the suffix cap without re-checking width
  • Skip validating end-letter input
  • Call printf("\n") inside either part loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print decreasing & increasing alphabet rows the beginner-friendly way.

5
Core concepts
> 02

Prefix

i..1 (skip A)

Code
0 03

Suffix

0..(n-i)

Code
= 04

Width

Always n+1

Shape
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

A is printed in the second loop. If the first loop included A, the join would duplicate A.
To keep each row the same width, end the ascending part at indices 0..(n − i). For A..E that is A + E − i, so both parts always add up to n+1 letters.
Yes. Set n = end − 'A' and keep the same loops: descending j from i down to 1, then ascending k from 0 to n − i.
O(n²) for n letters because there are n rows and each row prints O(n) characters.
The descending prefix has length i and the ascending suffix has length (n − i + 1). Together they always equal n + 1.
Check scanf(" %c", &end) == 1, require a single A–Z character, and reject invalid input.
Program 24 builds palindrome triangles around A. This page keeps fixed-width rows by trading a growing descending prefix against a shrinking ascending suffix.
The descending loop does nothing, so you print only the ascending suffix A..end — for E that is ABCDE.

Did you Know? 🔊

For 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.

Continue to Alphabet Pattern 31

Next up: V-shaped alphabet patterns that print letters only on two diagonals meeting at the bottom vertex.

Program 31 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful