Triangle with Reverse Starting Letter in C

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

What You’ll Learn

This pattern mixes ideas from program 1 and program 2: each row is longer than the last, the first character of each row moves backward in the alphabet, but along the row letters still run forward (A B C …).

With n = 5 and startChar = 'E', you get E, DE, CDE, BCDE, ABCDE.

⭐ Pattern Output

For 5 rows and top letter 'E':

Output
E
DE
CDE
BCDE
ABCDE
1

Complete C Program

Loop variable i is 0-based: row i begins at startChar - i, then j runs from 0 to i inclusive to print currentChar + j.

c
#include <stdio.h>

int main() {
    int n = 5;
    int i, j;
    char startChar = 'E';

    for (i = 0; i < n; ++i) {
        char currentChar = (char)(startChar - i);

        for (j = 0; j <= i; ++j) {
            printf("%c", (char)(currentChar + j));
        }

        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

n and startChar

n is the number of rows. startChar is the letter that appears on the right edge of the last row (here 'E').

Setup
2

First letter of the row

currentChar = startChar - i. When i is 0, 1, 2, … the row starts at E, D, C, …

Left edge
3

Print forward along the row

j from 0 to i: print currentChar + j. That is i + 1 letters on row i.

Inner loop
4

Why the last letter is always 'E'

Last character on row i is (startChar - i) + i = startChar. So every row ends at the same letter for this pattern.

Right edge
=

Reverse start, forward run

Work grows like 1+2+…+n, so time complexity is O(n²).

2

Variation — User Input Version

Read n with scanf(). Keep startChar = 'E' or derive it from n if you want the last row to end at a specific letter.

c
#include <stdio.h>

int main() {
    int n;
    int i, j;
    char startChar = 'E';

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

    for (i = 0; i < n; ++i) {
        char currentChar = (char)(startChar - i);

        for (j = 0; j <= i; ++j) {
            printf("%c", (char)(currentChar + j));
        }

        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Change startChar (e.g. 'Z') and watch the whole triangle shift
  • Use 'e' for a lowercase triangle
  • For the simple forward triangle A, AB, ABC, … see program 1
  • Try printing each row right-aligned with leading spaces

Avoid

  • Mixing up 0-based i with 1-based row counts when reasoning about startChar - i
  • Letting n so large that startChar - i goes before 'A' unless that is intentional
  • Using %d instead of %c for letters

Key Takeaways

1

currentChar = startChar - i moves the starting letter left along the alphabet each row.

2

printf("%c", currentChar + j) walks forward inside the row.

3

Algebra: last letter on row i is always startChar, so the right column is straight.

4

Same O(n²) cost as other triangle letter patterns.

❓ Frequently Asked Questions

Use currentChar = startChar - i with row index i starting at 0. The inner loop prints currentChar + j for j = 0 through i.
The last character is (startChar - i) + i = startChar. So with startChar == 'E', each row’s last letter is E.
Yes. Set startChar to any letter you want as the right edge (for consistent n). Ensure startChar - (n-1) is still a letter you are happy to print.
O(n²) for n rows: 1+2+…+n = n(n+1)/2 characters.

Explore More C Alphabet Patterns!

Character arithmetic plus nested loops unlock many interview-style shapes.

All Alphabet Patterns →
Did you know?

The identity (startChar - i) + j with j = i always equals startChar, which is why the right side of the triangle lines up vertically.

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