Reverse Repeating-Letter Triangle in C

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

What You’ll Learn

Same repeating idea as Program 9, but letters run E → D → C → B → A while row widths still grow 1, 2, 3, 4, 5. This tutorial covers the shape rule, letter formula, a live preview, worked C examples, edge cases, and complexity.

Shape Rule

Repeat letter, grow width

Row 1 prints E, row 2 prints DD, up to AAAAA on the last line.

Outer Loop

Rows + letter formula

for (i = 1; i <= rows; i++) walks each line; derive the letter from i.

Inner Loop

Repeat count

for (j = 1; j <= i; j++) prints ch exactly i times — not j.

printf vs putchar

Same line / next line

Letters use printf("%c", ch); end each row with printf("\n").

Live Preview

1–26 rows

Pick a row count and draw the reverse repeating triangle in the browser.

O(n²)

Complexity

Total letters = n(n+1)/2; extra memory stays O(1).

Introduction

A reverse repeating alphabet triangle grows by one repeated letter on each new line, counting letters downward from the top of the alphabet range. With the right angle on the left, the console shows a staircase of identical letters per row.

In C you usually solve it with two nested for loops: the outer loop picks the row index, ch = top - i + 1 picks the letter, the inner loop prints that letter i times, then printf("\n") moves to the next line.

Why it matters?

It locks in the difference between “which letter” (outer loop) and “how many times” (inner loop). Once that clicks, forward repeats, pyramids, and letter-countdown variants become much easier.

Key Highlights

Letters Count Down

Rows use E, then D, then C … down to A.

Width Still Grows

Row widths are still 1, 2, 3, … like Program 9.

Print Outer Letter

printf("%c", ch) in the inner loop; printf("\n") after.

Mirror of Program 9

Same shape — reverse letter direction only.

In short: for each row i, set ch = top - i + 1, print ch exactly i times, then call printf("\n").

📝 Problem & Approach

Given a positive integer rows (or a fixed top letter like 'E'), print a left-aligned triangle where each row repeats one letter and letters count downward.

c
// First 5 rows (conceptual shape)
// E
// DD
// CCC
// BBBB
// AAAAA

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines (typically 1–26). Top letter = 'A' + rows - 1.
Printed outputtextLeft-aligned rows; row k repeats letter top - (k-1) exactly k times.

Minimal workflow

Pseudocode
top = 'A' + rows - 1
for i from 1 to rows:
    ch = top - i + 1
    for j from 1 to i:
        print ch (no newline)
    print newline

Approach comparison

ApproachIdeaBest for
Nested int loops + formulach = top - i + 1, then print ch i timesLearning and interviews
putchar(ch)Write each letter without a format stringLeaner style after loops click

⚡ Quick Reference

GoalPattern
Walk each rowfor (i = 1; i <= rows; i++)
Letter for row ich = (char)(top - i + 1);
Print row letterprintf("%c", ch); — not j
End the rowprintf("\n");
putchar styleputchar(ch); then putchar('\n');
Forward lettersSee Program 9 (A, BB, CCC, …)

📋 printf vs putchar

Same triangle — different ways to emit characters.

printf("%c", ch)
same line

Prints the row letter without moving to the next line

printf("\n")
new line

Ends the current row after all repeats are printed

putchar(ch)
leaner char I/O

Writes one character without a format string

Learning tip
print ch

Master the formula and nested loops before polishing with putchar

Context

When This Pattern Shows Up

Reach for this triangle when practicing letter direction vs repeat count.

  1. After Program 9

    Flip letter direction while keeping the same growing widths.

  2. Outer vs inner roles

    Clear drill: outer = which letter, inner = how many copies.

  3. Char arithmetic practice

    Compute top = 'A' + rows - 1 and count down safely.

  4. Gateway to variants

    Lowercase, hollow borders, or centered pyramids next.

  5. Not a UI layout tool

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

Key benefit: one small program that separates letter choice from repeat count — the skill behind most alphabet patterns.

🔮 Live Preview

Choose a row count between 1 and 26 and draw the reverse repeating alphabet triangle in the browser.

Try 5 (E…A), 4 (D…A), or 7. Max 26 keeps letters in A–Z.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed top letter, scanf input, and a putchar shortcut. Click View Output to reveal sample console results.

📚 Getting Started

Print five rows with classic nested loops and ch = 'E' - i + 1.

Example 1 — Fixed 'E' down to 'A'

Hard-coded five rows — ideal for first demos and screenshots.

c
#include <stdio.h>

int main() {
    int i, j;
    char ch;

    for (i = 1; i <= 5; ++i) {
        ch = (char)('E' - i + 1);
        for (j = 1; j <= i; ++j) {
            printf("%c", ch);
        }
        printf("\n");
    }

    return 0;
}

How It Works

When i = 1, ch becomes 'E' and the inner loop prints it once. When i = 2, ch is 'D' and you get DD, and so on until AAAAA. Printing ch (not j) keeps each row uniform.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Compute startChar = 'A' + rows - 1, then ch = startChar - i + 1. Check scanf in real apps.

c
#include <stdio.h>

int main() {
    int rows, i, j;
    char ch;
    int startChar;

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

    startChar = 'A' + rows - 1;

    for (i = 1; i <= rows; ++i) {
        ch = (char)(startChar - i + 1);
        for (j = 1; j <= i; ++j) {
            printf("%c", ch);
        }
        printf("\n");
    }

    return 0;
}

How It Works

For rows = 4, startChar is 'D'. Row 1 prints D, row 2 prints CC, and so on. Clamp rows to 1–26 so startChar stays within A–Z. Check scanf’s return value in safer labs.

⚡ Shortcut Style

Same shape using putchar instead of printf for each letter.

Example 3 — putchar(ch)

Write each letter with putchar, then end the row with putchar('\n').

c
#include <stdio.h>

int main() {
    int i, j;
    char ch;

    for (i = 1; i <= 5; ++i) {
        ch = (char)('E' - i + 1);
        for (j = 1; j <= i; ++j) {
            putchar(ch);
        }
        putchar('\n');
    }

    return 0;
}

How It Works

putchar(ch) writes one character without a format string. Same nested-loop structure as Example 1; a leaner alternative to printf("%c", ch). Keep either style for exams that want both loop bounds visible.

🧠 How the Algorithm Prints Rows

1

Set up

#include <stdio.h> brings in printf / scanf. Fix the top letter (e.g. 'E') or compute it from rows.

Setup
2

Outer loop (letter)

for (i = 1; i <= rows; i++) selects the row; ch = top - i + 1 picks the letter.

E → A
3

Inner loop (count)

for (j = 1; j <= i; j++) prints ch with printf("%c", ch) exactly i times.

Repeats
4

New line

printf("\n") ends the row so the next outer iteration starts fresh with a new letter.

Break
=

Triangle complete

Total letters: 1+2+…+n = n(n+1)/2O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — 'E' down to 'A'

Trace each outer-loop row index i, the derived letter ch, and how many times the inner loop runs.

ichPrinted rowRepeats
1'E'E1
2'D'DD2
3'C'CCC3
4'B'BBBB4
5'A'AAAAA5

Total letter prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Outer vs Inner Clarity

Best demo that the printed value need not be the loop counter.

Example: swap printf("%c", ch) for something based on j and watch letters step.

2. Pair with Program 9

Teach direction as a one-line change: increment vs decrement.

Example: side-by-side A/BB/CCC vs E/DD/CCC.

3. Char Math Labs

Practice 'A' + rows - 1 without complex algorithms.

Example: rows = 7 → top = 'G'.

4. Case & Fill Variants

Swap to lowercase or mix digits once the loops work.

Example: start from 'a' + rows - 1.

5. Complexity Intuition

Triangular totals make O(n²) concrete for beginners.

Example: count printed letters for n = 10 → 55.

6. Input Validation Labs

Pair the pattern with checked scanf and 1–26 clamps.

Example: reject rows <= 0 or rows > 26.

Pro Tip: when explaining this pattern, say “outer picks the letter, inner only counts” before writing any code — that story prevents printing j by mistake.

Advantages

Why this pattern earns a spot right after the forward repeating triangle.

  1. 1. Instant Visual Feedback

    Wrong printed variable shows up immediately as stepping letters.

  2. 2. Minimal Concepts

    Only loops, chars, and console output — no arrays required.

  3. 3. Easy to Mirror

    Flip to Program 9 by counting letters upward instead.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: learn the nested-loop printf version first; treat putchar as a polish shortcut afterward.

Usage Tips

Small habits that keep alphabet-pattern code clean.

  1. 1. Name the Roles

    Use ch for the row letter and repeat (or k) for the count — clearer than overloaded i/j.

  2. 2. Check scanf

    Verify scanf returns 1 so bad input does not leave rows unset.

  3. 3. Keep the Newline Outside

    Only call printf("\n") after the inner loop finishes the row.

  4. 4. Clamp to 26

    For A–Z demos, reject or clamp rows > 26.

  5. 5. Dry-Run One Small n

    Trace rows = 3 (C, BB, AAA) on paper before coding larger demos.

Pro Tip: if a row shows EDCBA-style sequences, you almost certainly printed j instead of i.

Common Pitfalls

Mistakes that commonly break reverse repeating alphabet patterns.

  1. 1. Printing j Instead of i

    Rows become countdown sequences instead of repeated letters.

    → Always printf("%c", ch) for this shape — not j.

  2. 2. Newline Inside the Inner Loop

    Each letter lands on its own line — you get a column, not a triangle.

    → Use printf("%c", ch) for letters; printf("\n") only after the inner loop.

  3. 3. Forgetting the Row Break

    Omitting printf("\n") glues every letter onto one endless line.

    → Always end the row after the inner loop.

  4. 4. Unchecked scanf

    Letters or empty input leave rows uninitialized.

    → Check scanf’s return value and re-prompt on failure.

  5. 5. rows > 26 Without a Policy

    'A' + rows - 1 can leave the A–Z range.

    → Clamp to 26 or define wrap/error behavior explicitly.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A on one line.

rows = 0

Empty pattern

Treat as invalid; re-prompt instead of silent empty output.

Negative

rows < 0

Invalid height — validate before computing top.

rows > 26

Past Z

Clamp or error — char math leaves A–Z.

Bad input

Non-numeric input

Unchecked scanf fails silently — check the return value.

Case

Lowercase variant

Same loops work with 'a' and 'a' + rows - 1.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to Program 9

  • Count letters upward: A, BB, CCC, …
  • Continue with Program 9

2. Lowercase version

  • Use 'a' + rows - 1 as the top letter
  • Shows the loop structure is reusable

3. Safe input loop

  • Loop until scanf succeeds and 1 <= rows <= 26
  • Then draw the triangle

4. Hollow reverse triangle

  • Print the letter only on borders; spaces inside
  • Harder follow-up after this page

Notes

  • Triangular count. Total letters for n rows is n(n+1)/2 — hence O(n²) time.
  • Print the outer letter; the inner loop only decides how many times.
  • Validate 1 <= rows <= 26 for interactive A–Z programs.
  • This page is left-aligned. Centered pyramids need leading spaces — covered later in the series.

Quick Takeaway: outer loop picks the letter (counting down), inner loop repeats it, then break the line — that is the whole pattern.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
putchar (Example 3)O(rows²)O(1)
Wrap Up

🎉 Conclusion

The reverse repeating alphabet triangle is a small nested-loop exercise with lasting payoff: outer letter vs inner count, ch = top - i + 1, and O(n²) intuition. Master the classic two-loop version, then optionally polish letter output with putchar.

Practice the three examples above, then compare with Program 9 or continue to the next alphabet pattern.

Derive ch with top - i + 1, print with printf("%c", ch), end rows with printf("\n"), and clamp row counts to 1–26 when reading input.

💡 Best Practices

✅ Do

  • Explain outer = letter, inner = count before coding
  • Use printf("%c", ch) for letters and printf("\n") after each row
  • Validate 1 <= rows <= 26 for interactive programs
  • Check scanf’s return value instead of ignoring failed input
  • State O(n²) time when asked about complexity

❌ Don’t

  • Print the inner-loop variable for this repeating shape
  • Call printf("\n") inside the inner letter loop
  • Skip the newline after each row
  • Ignore bad console input in user-facing demos
  • Allow rows > 26 without a clear policy

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the reverse repeating triangle the beginner-friendly way.

5
Core concepts
02

Outer loop

Picks the row letter

Code
A 03

Inner loop

Repeats with printf

Code
04

Newline

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

Program 9 uses A, BB, CCC, ... (letters increase). Program 10 uses E, DD, CCC, ... (letters decrease) with the same growing repeat counts.
For i = 1..5 it yields E, D, C, B, A. Each row then prints that ch exactly i times.
Each row needs a different letter. Recalculating from i keeps the mapping simple without a separate ch++ countdown variable.
j only controls how many times the loop runs. Printing ch keeps the row the same letter; printing something that changes with j would change letters across the row.
printf("%c", ch) prints a letter and stays on the same line. printf("\n") ends the current line. Letters use %c; the row break uses \n after the inner loop.
O(n²) where n is the number of rows. Total letter prints equal 1+2+…+n = n(n+1)/2.
Yes. putchar(ch) writes one character without a format string. Nested loops with putchar are a common, slightly leaner style.
Check scanf's return value: if (scanf("%d", &rows) != 1) handle bad input. Then set startChar = 'A' + rows - 1 and use ch = startChar - i + 1. Clamp to 26 for A–Z demos.

Did you Know? 🔊

This pattern is the reverse of Program 9: row widths still grow 1, 2, 3, …, but letters run backward (E, then D, then C, …). Use ch = top - i + 1 then print ch exactly i times so each row stays uniform.

Continue to Alphabet Pattern 11

Keep building letter patterns with nested loops and char math.

Program 11 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