Sequential Decreasing Alphabet Triangle in C

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

What You’ll Learn

Shrink each row by one slot while a single k walks the alphabet without resetting—like program 22, but left-aligned and with shorter rows each time.

Prefer a monospace font so %2c columns align.

⭐ Pattern Output

Five rows, fifteen letters total (AO):

Output
A B C D E
F G H I
J K L
M N
O
1

Complete C Program ('A''E')

Character literals; inner index j only controls how many times k++ runs.

c
#include <stdio.h>

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

    for (i = 'A'; i <= 'E'; ++i) {
        for (j = 'E'; j >= i; --j) {
            printf("%2c", k++);
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

k walks forward through the alphabet

Initialize k = 'A' once. Each time you actually print a letter you use printf("%2c", k++), so the triangle is filled with a single increasing sequence rather than restarting at A every row.

Stream
2

Outer i picks the row’s low letter

i runs AE. It becomes the smallest letter that may appear on that row; letters below i in the alphabet are skipped by the inner loop bound.

Rows
3

Inner j from E down to i

Counting down from the top letter to the row floor gives a shorter slice each time i rises. The iteration count is 'E' - i + 1, which is 5, 4, 3, 2, 1 for this sample.

Width
4

%2c for alignment

A width-two conversion adds leading space before single letters so the right-aligned triangle matches the tutorial diagram and stays readable on small screens when you scroll horizontally if needed.

Align
=

Triangular total

Letter prints sum to 5+4+3+2+1 = 15, the fifth triangular number. Nested loops yield O(n²) character output for n rows in this style.

2

Variation — User Input

endChar = (char)('A' + rows - 1); inner j runs endChar down to i.

c
#include <stdio.h>

int main() {
    int rows;
    int i, j;
    char k = 'A';
    char startChar, endChar;

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

    startChar = 'A';
    endChar = (char)('A' + rows - 1);

    for (i = startChar; i <= endChar; ++i) {
        for (j = endChar; j >= i; --j) {
            printf("%2c", k++);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Widen columns with %3c or use "%c " if you prefer explicit gaps
  • Start at 'a' for lowercase
  • Keep rows small enough that k never passes 'Z'

Avoid

  • Resetting k each row (you would repeat A B C D E every line)
  • Choosing rows so required letters exceed your alphabet range

Key Takeaways

1

Inner loop count per row: endChar - i + 1 (with endChar = 'E' in the fixed example).

2

Total characters for n rows from a fresh A: n(n+1)/2.

3

j can be ignored in the body; it only schedules how many k++ prints occur.

4

O(n²) characters for n rows.

❓ Frequently Asked Questions

The pattern is one continuous sequence across the triangle. Resetting would start each row at A again.
Yes, as long as it runs the same number of times (e.g. for (j = 0; j < endChar - i + 1; j++)). Descending j matches the fixed Ei style from the ASCII version.
Program 24 builds palindrome strings with two letter loops per row and plain %c. Here each row is a straight segment of the global k stream with %2c spacing.
O(n²) printed characters for n rows (triangular total).

Explore More C Alphabet Patterns!

Using the inner index only as a repetition count while a separate variable supplies the symbol is a common pattern idiom.

All Alphabet Patterns →
Did you know?

For n rows with last row letter L, you need L - 'A' + 1 = n(n+1)/2 letters from A; for n = 5 that ends at 'O'.

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