C Repeating Alphabet Triangle Pattern (Inverted)

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

What Is This Pattern?

An inverted repeating alphabet triangle prints a wide first row of one letter, then shrinks by one repeated letter on each new line while letters count down.

Remember
Rule: width i from rows down to 1;
      print ch exactly i times, then ch--

EEEEE
DDDD
CCC
BB
A         ← 5 rows (start ch = 'E')

It is the flip of Program 10: same countdown letters, but widths shrink 5, 4, 3, …, 1 instead of growing. Print ch in the inner loop, then ch-- after each row so every line stays uniform.

How to Solve It

Two ways to emit the same shape — start with nested loops + ch--, then optionally polish with putchar.

MethodIdeaBest for
Nested loops + ch--Outer = shrinking width; print ch, then decrementLearning, interviews, exams
putchar(ch)Same loops; write each letter without a format stringShorter demos once loops click

Pseudocode

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

Cheat sheet

GoalPattern
Shrink widthfor (i = rows; i >= 1; i--)
Repeat letterfor (j = 1; j <= i; j++) printf("%c", ch);
Uniform rowPrint ch, not j
End row + step letterprintf("\n"); ch--;
Top from rowsch = 'A' + rows - 1;
putchar styleputchar(ch); … putchar('\n'); ch--;
Growing twinProgram 10 (E, DD, CCC, …)

Printing Letters vs Starting a New Line

APIEffectUse for
printf("%c", ch)Stays on the same lineEach letter on the row
printf("\n")Ends the current lineAfter the inner loop (before ch--)

Print characters without a newline, then end the row once.

Live Preview

Change the height and the inverted triangle updates instantly — including the letter total.

Whole numbers from 1 to 26 (A–Z). Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · 15 letters
EEEEE
DDDD
CCC
BB
A

Worked Walkthrough — rows = 5, start ch = 'E'

Trace each outer-loop width i and the letter printed on that row.

i (width)chPrinted rowThen
5'E'EEEEEch-- → 'D'
4'D'DDDDch-- → 'C'
3'C'CCCch-- → 'B'
2'B'BBch-- → 'A'
1'A'Adone

Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. That triangular sum is why time is O(n²).

C Programs

Three complete programs: fixed letters, scanf input, and a putchar variant. Use View Output to reveal sample results.

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

Hard-coded height — outer width shrinks; print ch, then ch-- after each row.

C
#include <stdio.h>

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

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

    return 0;
}

How It Works

1. Start at the top letter. ch = 'E' and i = 5 mean the first row is five Es.

2. Outer loop shrinks the width. i runs from 5 down to 1.

3. Inner loop prints ch. j runs from 1 to i; each time prints the current letter (not j).

4. Break the line, then step the letter. printf("\n") ends the row; ch-- prepares D, C, … for the next shorter row.

Example 2 — User Input Version

Set ch = 'A' + rows - 1, then loop i from rows down to 1. Check scanf in real apps.

C
#include <stdio.h>

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

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

    ch = 'A' + rows - 1;

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

    return 0;
}

How It Works

1. Prompt and read. Ask for a row count with scanf("%d", &rows).

2. Compute the top letter. For rows = 4, ch starts at 'D' — first row is DDDD.

3. Same shrink core. Only the source of rows / starting ch changes — the print logic matches Example 1.

4. Safer input tip. Unchecked scanf can leave rows unset. 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 — putchar(ch)

Same shape with putchar instead of printf("%c", …) for each letter.

C
#include <stdio.h>

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

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

    return 0;
}

How It Works

1. Same nested structure. Still shrink i, print ch i times, then ch--.

2. Write characters directly. putchar(ch) and putchar('\n') avoid format strings for single characters.

3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

printf("%c", j)

Stepping letters on a row

If you print j (or a letter based on j) instead of ch, the row is no longer uniform. Always print ch.

ch-- inside

Letters change mid-row

Put ch-- after the inner loop and newline. Decrementing inside the letter loop steps characters across the row.

\n inside

Column of letters

If printf("\n") is inside the inner loop, each letter lands on its own line. End the row only after all repeats.

rows > 26

Past Z

'A' + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.

rows = 1

Single A

Output is just A — top and tip coincide. A good sanity check.

Bad input

Check scanf

Verify scanf returns 1 and require 1 <= rows <= 26.

Time and Space Complexity

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

Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — still quadratic in n. Same totals as Program 10; only the print order of widths differs.

Key Takeaways

  • Rule: shrink width i; print ch exactly i times; then ch--.
  • Flip of Program 10: same letters — widths shrink instead of grow.
  • Break the row: printf("\n") (or putchar('\n')) only after the inner loop.
  • Complexity: O(n²) time from the triangular letter count; O(1) extra space.

One line: for i from rows down to 1, print ch i times, print newline, then ch--.

Frequently Asked Questions

Program 10 prints widths 1..5 (E, DD, CCC, ...). Program 11 prints widths 5..1 (EEEEE, DDDD, ...). Both use repeating letters per row and letters counting down.
i starts at 5 so the first inner loop runs five times while ch is E. After the row, ch becomes D and i is 4, so the next line prints D four times.
So every column on a row shows the same letter. Decrementing inside the inner loop would step letters across the row.
j only controls how many times the loop runs. Printing ch keeps the entire row the same letter; printing j would step 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 n+(n-1)+…+1 = 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 ch = 'A' + rows - 1 and loop i from rows down to 1 with ch-- after each row. Clamp to 26 for A–Z demos.

Did you know?

This is the inverted twin of Program 10: letters still step E→A, but widths shrink 5, 4, 3, …, 1 instead of growing. Print ch in the inner loop, then ch-- after each row so every line stays uniform.

Next: Inverted Forward Repeats

Keep shrinking widths, but step letters forward from A instead of counting down.

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