C Alphabet Triangle Pattern (Reverse Order)

Beginner
6 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A reverse-order alphabet triangle prints a left-aligned staircase where each row’s highest letter grows forward, but letters along the row print backward down to A.

Remember
Rule: on row with peak i, print i down to A

A
BA
CBA
DCBA
EDCBA     ← 5 rows

It is the row-order flip of Program 1: same growing widths, but the inner loop counts down instead of up. Compare with Program 3, which changes the start letter while still printing forward.

How to Solve It

Two ways to emit the same shape — nested char loops, or the same loops with spaced letters for readability.

MethodIdeaBest for
Nested char loopsOuter = peak letter; inner = peak down to ALearning, interviews, exams
Spaced lettersSame loops; print "%c " per letterEasier column scanning once loops click

Pseudocode

Pseudocode
for peak from 'A' to lastLetter:
    for ch from peak down to 'A':
        print ch (no newline)
    print newline

Cheat sheet

GoalPattern
Walk each peakfor (i = 'A'; i <= last; i++)
Print i..Afor (j = i; j >= 'A'; j--) printf("%c", j);
End the rowprintf("\n");
Last letter from rowschar last = 'A' + rows - 1;
Spaced lettersprintf("%c ", j);
Forward twinProgram 1 (j from A up to i)
Reverse start, forward runProgram 3

Printing Letters vs Starting a New Line

APIEffectUse for
printf("%c", j)Stays on the same lineEach letter (and optional space)
printf("\n")Ends the current lineAfter the inner loop finishes a row
putchar(j)Same as printing one characterOptional leaner style once loops click

Live Preview

Change the row count and the reverse-order triangle updates instantly — every row ends at A.

Whole number from 1 to 10. Tap a chip or type a count — the preview redraws as you go.

Live result 5 rows · peak E · 15 letters
A
BA
CBA
DCBA
EDCBA

Worked Walkthrough — Top = E (5 rows)

Trace each peak letter and the resulting reverse run down to A.

i (peak)Inner rangePrinted row
AA..AA
BB..ABA
CC..ACBA
DD..ADCBA
EE..AEDCBA

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

C Programs

Three complete programs: fixed top E, row-count input with scanf, and spaced letters. Use View Output to reveal sample results.

Example 1 — Fixed Top E

Outer loop picks the highest letter on each row; inner loop prints from that letter down to 'A'.

c
#include <stdio.h>

int main(void) {
    char i, j;

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

    return 0;
}

How It Works

1. Outer loop raises the peak. i runs from 'A' to 'E' — one peak letter per row.

2. Inner loop prints backward. For each row, j runs from i down to 'A'. When i = 'C', that prints CBA.

3. Break the line. printf("\n") after the inner loop ends the row.

4. Full last row. When i = 'E', the inner loop prints the full reverse run EDCBA.

Example 2 — Row Count Input

Read the number of rows and loop i from 'A' to 'A' + rows - 1. Check scanf in real apps.

c
#include <stdio.h>

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

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

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

    return 0;
}

How It Works

1. Scale the peak. For 4 rows, i runs through A..D. Cap rows at 26 so the peak stays within A–Z.

2. Same core loops. Only the stop letter changes; the peak-grows / print-backward rule is unchanged.

3. Safer input tip. Prefer:

Safer input
if (scanf("%d", &rows) != 1 || rows < 1 || rows > 26) {
    printf("Enter a whole number from 1 to 26.\n");
    return 1;
}

Example 3 — Spaced Letters

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

c
#include <stdio.h>

int main(void) {
    char i, j;

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

    return 0;
}

How It Works

1. Same bounds. Loop limits are unchanged — only the printed unit becomes "%c ".

2. Optional trim. Trim trailing spaces later if you need a compact line for grading scripts.

Edge Cases & Pitfalls

Check these before calling the solution done.

Inner j++

Wrong direction on the row

If the inner loop counts up, you get Program 1 (A, AB, ABC). Keep j-- from i down to 'A'.

Outer --

Shrinking from E instead

If the outer loop runs E..A with the same inner rule, you print an inverted reverse triangle. Start at A and go up.

printf("\n") inside

Column of letters

If printf("\n") is inside the inner loop, each letter lands on its own line. Print letters with %c; break the line only after the row.

rows = 1

Single A

When the peak is 'A', you print one row: A. A good sanity check.

rows > 26

Beyond Z

Cap at 26 (or reject) so the peak letter stays within A–Z.

scanf

Check return value

scanf("%d", &rows) can fail on empty or non-numeric text. Check == 1 and validate the range.

Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(n²)O(1)
Spaced letters (Example 3)O(n²)O(1)

For n rows, total letters are 1 + 2 + … + n = n(n + 1)/2 — still quadratic in n.

Key Takeaways

  • Rule: peak letter grows A → top; print that letter down to A.
  • Fixed right edge: every row ends at A.
  • Break the row: call printf("\n") only after the inner loop.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each peak from A up to top, print that letter backward down to A.

Frequently Asked Questions

The outer loop selects the highest letter on the row (A to E). The inner loop starts at that letter and decrements down to 'A', printing each character, so each row reads backward.
Because the inner loop always runs until j == 'A', so the last printed character on every row is A.
Program 1 prints forward along each row (A, AB, ABC). This pattern prints backward down to A (A, BA, CBA) while the left edge still grows A, B, C, …
Program 3 starts earlier each row but still prints forward to a fixed top (E, DE, CDE). This pattern starts later each row and prints backward to a fixed A.
O(n²) for n rows, because the total printed letters are 1+2+...+n = n(n+1)/2.
Yes. Read rows with scanf and loop i from 'A' to 'A' + rows - 1, with the inner loop counting down from i to 'A'.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the highest letter stays within A–Z.
Yes. Start from 'a' and loop the same way: outer i from 'a' up, inner j from i down to 'a'.

Did you know?

Each row starts one letter later (A, B, C, …), but prints backward down to A. For 5 rows, the output is A, BA, CBA, DCBA, EDCBA — the reverse of Program 1’s row order.

Next: Inverted Alphabet Triangle

Flip the outer loop so the end letter shrinks while letters still print forward from A.

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