Inverted Right-Angled Alphabet Triangle in C

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

What You’ll Learn

Print an inverted alphabet right-angled triangle: the first row is the longest (ABCDE for five rows), and each next row removes one letter while still starting from 'A'. This is the partner to Program 1 — only the outer loop direction changes. Compare also with Program 4. Includes a live preview, worked C examples, edge cases, and complexity.

Shape Rule

Rows shrink

First row longest; each next row loses one letter.

Outer Loop

i-- from top

End letter moves E → A to shrink width.

Inner Loop

A..i

Same forward prefix as Program 1 every row.

vs Program 1

Invert

Flip only the outer loop to grow instead of shrink.

Live Preview

Rows 1–10

Pick a row count and draw ABCDE…A live.

O(n²)

Complexity

n+(n-1)+…+1 printed characters total.

Introduction

An inverted alphabet triangle is Program 1 turned upside down: start with the full prefix, then drop one letter from the end on each following row.

In C you count the outer bound down (i--) while the inner loop still prints from 'A' up to i.

Why it matters?

It shows that growing vs shrinking triangles are often the same inner loop with opposite outer bounds — a key nested-loop insight.

Key Highlights

Outer

i from top down to A.

Inner

j from A up to i.

Edge

Every row starts at A.

Output

ABCDE … A

In short: for each end letter i from top down to 'A', print j from 'A' up to i, then call printf("\n").

📝 Problem & Approach

Given a row count (or fixed top E), print an inverted right-angled triangle where each row is an A-prefix that gets shorter.

c
// Five rows (top = E)
// ABCDE
// ABCD
// ABC
// AB
// A

Inputs & Outputs

ItemTypeDescription
rows / topint / charNumber of rows; top letter is 'A' + rows - 1 (E for 5).
Printed outputtextShrinking forward prefixes from A..top down to A.

Minimal workflow

Pseudocode
top = 'A' + rows - 1
for i from top down to 'A':     // end letter shrinks
    for j from 'A' to i:        // forward prefix each row
        print j
    print newline

Approach comparison

ApproachIdeaBest for
Char nested loopsOuter i--, inner j++ from A to iMatching this classic sample
Row index + lengthFor r = n..1 print first r letters of the alphabetWhen thinking in lengths instead of end letters

⚡ Quick Reference

GoalPattern
Fixed A–Efor (char i = 'E'; i >= 'A'; i--)
Forward prefixfor (char j = 'A'; j <= i; j++) printf("%c", j);
User rowschar top = (char)('A' + rows - 1); then loop i from top down
Growing insteadSee Program 1 (outer i++)
Reverse along rowSee Program 4

📋 Prog 1 vs Prog 4 vs Prog 5

Same alphabet prefixes — different growth and letter direction.

Program 1
grow A..i

A, AB, ABC — outer i++

Program 4
grow i..A

A, BA, CBA — reverse along row

Program 5
shrink A..i

ABCDE, ABCD, A — outer i--

printf("\n")
break

Ends the row after A..i finishes

Context

When This Pattern Shows Up

Reach for this when teaching a shrinking end bound with a forward A-prefix each row.

  1. After Program 1

    Keep the same inner loop; flip only the outer direction.

  2. Inverted star drills

    Same geometry as inverted star triangles, with letters.

  3. Bridge to Program 6

    Next shrinks from the left instead: ABCDE, BCDE, CDE, …

  4. Char arithmetic practice

    Mix i-- with j++ in the same program.

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one descending outer bound plus Program 1’s inner loop is the cleanest way to invert a growing alphabet triangle.

🔮 Live Preview

Choose 1–10 rows and draw the inverted alphabet triangle in the browser.

Try 5 (classic ABCDE…A) or 4 (ABCD…A). Max 10 keeps the preview readable.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed A–E, scanf row count, and a spaced-letter variant. Click View Output to reveal sample console results.

📚 Getting Started

Print five shrinking rows that always start at A.

Example 1 — Fixed Top E

Outer loop shrinks the row by decreasing the end letter from 'E' to 'A'. Inner loop always prints from 'A' up to that end letter.

c
#include <stdio.h>

int main() {
    char i, j;

    for (i = 'E'; i >= 'A'; i--) {
        for (j = 'A'; j <= i; j++) {
            printf("%c", j);
        }
        printf("\n");
    }

    return 0;
}

How It Works

When i = 'C', the inner loop prints A, B, CABC. When i = 'A', it prints only A.

📈 Practical Variant

Let the user choose how many rows to print.

Example 2 — Row Count Input

Read the number of rows and compute top = 'A' + rows - 1. Check scanf in real apps.

c
#include <stdio.h>

int main() {
    int rows;
    char top, i, j;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    top = (char)('A' + rows - 1);
    for (i = top; i >= 'A'; i--) {
        for (j = 'A'; j <= i; j++) {
            printf("%c", j);
        }
        printf("\n");
    }

    return 0;
}

How It Works

For 4 rows, top becomes 'D'. Cap rows at 26 so top stays within A–Z.

⚡ Readability Variant

Same triangle with spaces between letters.

Example 3 — Spaced Letters

Print a trailing space after each letter so columns are easier to scan.

c
#include <stdio.h>

int main() {
    char top = 'E';
    char i, j;

    for (i = top; i >= 'A'; i--) {
        for (j = 'A'; j <= i; j++) {
            printf("%c ", j);
        }
        printf("\n");
    }

    return 0;
}

How It Works

Loop bounds are unchanged — only the printed unit becomes j + " ". Trim trailing spaces later if you need a compact line.

🧠 How the Algorithm Prints Rows

1

Outer loop shrinks the width

i runs from top down to 'A'. That means the first row has the most letters and each next row has one fewer.

Row width
2

Inner loop always starts at A

For each row, j starts at 'A' and goes up to i, so every row begins with A.

Fresh prefix
3

New line

printf("\n") ends the row before the next (shorter) row prints.

Line break
4

Left edge stays A

Because the inner loop always starts at 'A', every row begins on A while the right edge moves left.

Alignment
=

Inverted triangle

Total printed characters are still n+(n-1)+…+1, so time complexity is O(n²).

🔎 Worked Walkthrough — Top = E (5 rows)

Trace each end letter and the resulting forward prefix from A.

i (end)Inner rangePrinted row
EA..EABCDE
DA..DABCD
CA..CABC
BA..BAB
AA..AA

Row lengths are 5, 4, 3, 2, 1. The left edge is always A.

Use Cases

Where this inverted alphabet triangle shows up beyond the homework prompt.

1. Invert Labs

Clearest demo of flipping only the outer loop.

Example: change i-- to i++ and compare with Program 1.

2. Prefix Practice

Fixed left edge (A) with a moving right edge.

Example: stack next to Program 6’s moving left edge.

3. Char Bounds

Practice inclusive descending outer ranges ending at 'A'.

Example: off-by-one if you stop at 'B'.

4. Input Scaling

Map row count to top letter with 'A' + rows - 1.

Example: scale from 5 to 8 without rewriting loops.

5. Complexity Intuition

Triangle sums make O(n²) easy to see.

Example: 15 letters for 5 rows.

6. Series Continuity

Sits between Programs 4 and 6 in the alphabet set.

Example: revisit Program 1.

Pro Tip: say “start at the full prefix, then shorten the end letter” before coding — that story prevents writing a growing outer loop by habit.

Advantages

Why this pattern earns a spot early in the alphabet-pattern series.

  1. 1. Instant Visual Feedback

    A growing triangle or missing A shows up immediately.

  2. 2. Tiny Diff from Program 1

    Only the outer step direction changes.

  3. 3. Scales Cleanly

    Change the top letter or row count and the whole triangle shrinks from there.

  4. 4. Beginner-Friendly

    No padding or diagonal checks — just two char loops.

Pro Tip: master Program 1 first; this page is mostly “same inner loop, count the outer bound down.”

Usage Tips

Small habits that keep inverted alphabet triangles clean.

  1. 1. Count Down to A Inclusive

    Use i >= 'A' so the last row still prints A.

  2. 2. Always Start the Inner Loop at A

    Starting at a moving letter turns this into Program 6 instead.

  3. 3. Set top = 'A' + rows - 1

    Forgetting the - 1 makes the first row one letter too long.

  4. 4. Cap Rows at 26

    Keep the top letter inside A–Z when taking user input.

  5. 5. Check scanf

    Validate the row count and check scanf’s return value.

Pro Tip: if you see A, AB, ABC, the outer loop is still incrementing — switch to i-- from top.

Common Pitfalls

Mistakes that commonly break inverted alphabet triangles.

  1. 1. Using i++ in the Outer Loop

    Prints Program 1 instead of ABCDE, ABCD, …

    → Use for (char i = top; i >= 'A'; i--).

  2. 2. Starting the Inner Loop at i

    Produces Program 6-style suffixes (BCDE, CDE, …).

    → Always start at j = 'A'.

  3. 3. Wrong top Formula

    Using 'A' + rows without - 1 overshoots.

    → Use top = (char)('A' + rows - 1).

  4. 4. Unchecked scanf

    Empty or non-numeric input leaves rows unused or uninitialized.

    → Check scanf’s return value and validate range.

  5. 5. Forgetting printf("\n")

    All letters dump onto one line.

    → Call printf("\n") after each inner loop.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A.

rows = 5

Classic sample

ABCDE down to A (Example 1).

rows = 4

Smaller triangle

ABCD down to A (Example 2).

rows > 26

Past Z

Cap or reject — top leaves the alphabet.

Bad input

Empty / non-numeric

Check scanf’s return value.

Lowercase

abcde … a

Swap 'A' for 'a' in both loops.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to Program 1

  • Change only the outer loop to i++
  • Confirm you get A, AB, ABC

2. Compare with Program 6

  • Start the inner loop at i instead of 'A'
  • See Program 6

3. Scale to 8 rows

  • Use the input version
  • Check the first row is ABCDEFGH

4. Right-align with spaces

  • Print leading spaces before the letters
  • Keep the A..i run unchanged

Notes

  • End shrinks. Outer i-- shortens each row from the right.
  • The inner loop always starts at 'A', so the left edge is vertical.
  • Row lengths are n, n-1, …, 1 — the inverse of Program 1.
  • Next up: Alphabet Pattern 6 moves the start letter instead.

Quick Takeaway: shrink the end letter with the outer loop, then print from A up to that bound — that alone builds ABCDE, ABCD, …, A.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Inline / input (Examples 1–2)O(n²)O(1)
Spaced letters (Example 3)O(n²)O(1)

For n rows you print n+(n-1)+…+1 = n(n+1)/2 characters, so total work is O(n²).

Wrap Up

🎉 Conclusion

The inverted alphabet triangle is Program 1 with a descending outer loop: the end letter shrinks E…A while each row still prints forward from A. Master the classic ABCDE…A sample, then try user input and the spaced rewrite.

Practice the three examples above, then continue to Alphabet Pattern 6.

Outer i from top down to A, inner j from A up to i, then break each line.

💡 Best Practices

✅ Do

  • Start the outer loop at top and count down to 'A'
  • Keep the inner loop starting at 'A'
  • Use top = 'A' + rows - 1 for input versions
  • Cap user row counts at 26
  • State O(n²) when asked about complexity

❌ Don’t

  • Use i++ when you want ABCDE, ABCD, …
  • Start the inner loop at i (that becomes Program 6)
  • Forget the - 1 in the top formula
  • Skip validating row-count input
  • Call printf("\n") inside the letter loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the inverted alphabet triangle the beginner-friendly way.

5
Core concepts
= 02

Inner

j from A to i

Code
1 03

Edge

Every row starts at A

Shape
R 04

vs Prog 1

Only outer flips

Compare
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The outer loop counts down so the first row prints the most letters and each next row prints one fewer. The inner loop still prints from A up to the current bound.
Because the inner loop always starts at 'A'. That resets the sequence each row, producing ABCDE then ABCD and so on.
Program 1 grows row length (A, AB, ABC). This pattern shrinks it (ABCDE, ABCD, ABC). Only the outer loop direction changes; the inner loop is the same A..i print.
Program 4 grows while printing backward (A, BA, CBA). This pattern shrinks while printing forward from A (ABCDE, ABCD, ABC).
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. Read rows with scanf, set top = (char)('A' + rows - 1), then loop i from top down to 'A' and print j from 'A' up to i.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
Yes. Use 'a' as the base: top = (char)('a' + rows - 1), then loop the same way with j++ from 'a' up to i.

Did you Know? 🔊

This is the inverted version of the usual growing alphabet triangle. For 5 rows, it prints ABCDE, ABCD, ABC, AB, A by shrinking the row length each line while still starting from 'A'.

Explore More C Alphabet Patterns!

Inverted shapes are a small loop change away from the standard triangle.

All Alphabet Patterns →

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