Inverted Forward Repeating Triangle in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

Row width shrinks from five to one, but the letter moves forward each row: AAAAA, BBBB, CCC, DD, E.

Compare program 11 (same shape, letters step down with ch--) and program 9 (width grows with ch++).

⭐ Pattern Output

For 5 rows:

Output
AAAAA
BBBB
CCC
DD
E
1

Complete C Program (Fixed Rows)

i controls width (5 down to 1). ch starts at 'A'; after each full row, move to the next letter with ch++.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

ch = 'A'

The widest row starts at A. Unlike program 11, the letter moves forward (ch++) as the rows get shorter, so you read AAAAA, BBBB, … down to one E.

Setup
2

Outer loop i = 5 .. 1

Decreasing i shrinks the row width each time while you still print a single repeated letter per row. Geometry matches an inverted triangle of repeats.

Inverted
3

Inner loop: uniform row

The inner index only controls the count. Each printf("%c", ch) uses the same ch for that row, so you never mix letters on one line.

Repeat
4

New line, then ch++

After each row, a newline resets the cursor. Incrementing ch picks the next letter for the shorter row that follows.

Next letter
=

Count and complexity

Again 5+4+3+2+1 characters. In general n(n+1)/2 prints for n starting width, so the nested loops are O(n²).

2

Variation — User Input Version

Keep ch = 'A'; only the outer bounds use rows (same logic as the fixed version).

c
#include <stdio.h>

int main() {
    int rows, i, j;
    char ch = 'A';

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Stateless form: ch = (char)('A' + rows - i) at the top of each outer iteration (no ch++ variable)
  • Reverse letters on the same shape: program 11
  • Validate rows so ch does not pass 'Z' if you extend the idea

Avoid

  • ch++ inside the inner loop unless you want a diagonal staircase
  • Skipping ch++ so every row stays A

Key Takeaways

1

Inverted width (5→1) plus ch++ after each row gives forward letters on a shrinking triangle.

2

ch++ once per row keeps each line uniform.

3

O(n²) characters for n rows.

4

Dual of program 11; same structure as program 9 with the outer loop reversed.

❓ Frequently Asked Questions

i starts at 5, so the inner loop runs five times while ch is still 'A'.
Yes—after the row is printed. Putting it right after printf("\n") matches program 9’s style.
ch = 'A', then for (i = rows; i >= 1; --i) with the same inner loop and ch++ after each row.
O(n²) for n rows.

Explore More C Alphabet Patterns!

Inverted triangle plus forward letters is a small change from program 11 with a different feel.

All Alphabet Patterns →
Did you know?

With rows fixed, you can set ch = (char)('A' + rows - i) at the start of each outer iteration while i runs rows down to 1—no ch++ variable needed.

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