Reverse Order Alphabet Triangle in C

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

What You’ll Learn

Build a right-angled triangle where the first character of each row moves forward in the alphabet (A, B, C, D, E), but each row is printed backward down to A: A, BA, CBA, DCBA, EDCBA.

Compare with program 1 (forward A, AB, ABC, …) and program 3 (left edge moves backward, letters forward along the row).

⭐ Pattern Output

For 5 rows:

Output
A
BA
CBA
DCBA
EDCBA
1

Complete C Program (Fixed Rows)

Use rows = 5. For each 0-based row index i, set currentChar = 'A' + i, then print currentChar - j for j = 0 to i.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Outer loop: row index i

i runs from 0 to rows - 1. Row i will contain i + 1 characters.

Rows
2

High letter for this row

currentChar = 'A' + i is the leftmost (highest) letter on the row: A, B, C, D, E as i increases.

Left edge
3

Inner loop: step down

printf("%c", currentChar - j) for j from 0 to i prints from the row’s high letter down toward A.

Reverse along row
4

Right edge is always A

When j == i, you print ('A' + i) - i = 'A'. So the last character of every row is A.

Algebra
=

Triangle shape

Same O(n²) work as other letter triangles: 1+2+…+n characters for n rows.

2

Variation — User Input Version

Read rows with scanf(); the same logic applies for any positive rows (watch that 'A' + i stays in the range you want).

c
#include <stdio.h>

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

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Use 'a' instead of 'A' for lowercase output
  • For A, AB, ABC, … see program 1 or replace the inner print with printf("%c", (char)('A' + j)) on each row
  • Right-align the triangle with spaces if you want a pyramid-style layout
  • Validate scanf results and reject negative or huge row counts

Avoid

  • Using currentChar + j when you want descending letters inside the row
  • Letting rows so large that 'A' + i leaves the letter range you intend
  • Mixing 0-based i with formulas written for 1-based row numbers without adjusting

Key Takeaways

1

currentChar = 'A' + i raises the starting letter each row.

2

currentChar - j prints backward along the row as j increases.

3

The last character on row i is always 'A'.

4

Time complexity O(n²) for n rows.

❓ Frequently Asked Questions

currentChar is 'A' + i. The inner loop prints currentChar - j for j from 0 through i, so each step subtracts one from the letter.
Adding j would walk forward in the alphabet (C, D, E on row starting at C). This pattern needs to walk backward to A.
Use program 1, or on each row print 'A' + j for j from 0 to i instead of currentChar - j.
O(n²) for n rows.

Explore More C Alphabet Patterns!

Small changes to + and - on characters produce very different shapes.

All Alphabet Patterns →
Did you know?

Here the left column reads A, B, C, D, E while the right column is all A—the mirror image of patterns where the right column is fixed and the left moves.

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