Inverted Right-Angled Alphabet Triangle in C

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

What You’ll Learn

Print an inverted letter triangle: the first row is the longest (ABCDE for five rows), then each row drops one letter while still starting from 'A' and counting up.

This is the natural partner to program 1 (growing rows); only the outer loop direction changes.

⭐ Pattern Output

For 5 rows:

Output
ABCDE
ABCD
ABC
AB
A
1

Complete C Program (Fixed Rows)

Outer loop: i from rows down to 1. Before the inner loop, set currentChar = 'A'; inner loop runs i times printing and incrementing.

c
#include <stdio.h>

int main() {
    int rows = 5;
    int i, j;
    char currentChar;

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

    return 0;
}

🧠 How It Works

1

Reverse outer loop

for (i = rows; i >= 1; --i) makes the first printed line use the largest i (widest row).

Width shrinks
2

Restart at A each line

currentChar = 'A' at the beginning of each outer iteration so every row reads A, AB, ABC, … not a continued alphabet.

Fresh prefix
3

Inner loop length = i

for (j = 1; j <= i; ++j) prints exactly i letters on this line.

Inner count
4

New line

printf("\n") after the inner loop ends the row before i decreases.

Line break
=

Inverted triangle

Total characters: rows + (rows-1) + ... + 1 = rows(rows+1)/2O(n²) for rows = n.

2

Variation — User Input Version

Read rows with scanf(); the same nested loops apply.

c
#include <stdio.h>

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

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Use for (i = 1; i <= rows; ++i) to get the growing triangle again (program 1)
  • Start each row from 'a' for lowercase
  • Omit currentChar = 'A' each row to see a continuous alphabet across lines (different pattern)
  • Validate scanf and reject invalid row counts

Avoid

  • Forgetting to reset currentChar when you want every row to start at A
  • Using i++ on the outer loop when you need the width to shrink
  • Confusing “row number” with loop variable i when reading traces

Key Takeaways

1

i from rows down to 1 gives decreasing line lengths.

2

Reset currentChar to 'A' before printing each line so prefixes stay A, AB, ABC, …

3

Same total work as program 1: O(n²) characters for n rows.

4

Mirrors inverted star pattern 2 logic with letters instead of *.

❓ Frequently Asked Questions

i starts at rows and counts down. The inner loop runs i times, so the first line is longest and each following line is shorter.
So each line is a fresh A-prefixed run. Without it, letters would continue after F, G, … across lines.
Program 1 uses i from 1 to rows (lines grow). Here i goes from rows to 1 (lines shrink). Inner printing from A upward is the same idea.
O(n²) for n rows.

Explore More C Alphabet Patterns!

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

All Alphabet Patterns →
Did you know?

If you only change the outer loop between program 1 and program 5, you reuse the same inner “print from A for i columns” idea—a good sign your code is structured well.

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