Right-Angled Triangle Alphabet Pattern in C

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

What You’ll Learn

How to print an alphabet right-angled triangle in C: each row starts at 'A' and adds one more letter than the previous row, using nested for loops and printf("%c", ch++).

With five rows, the output is A, then AB, then ABC, up through ABCDE—a direct analogue of the star triangle, but with letters.

⭐ Pattern Output

For 5 rows, the pattern looks like this:

Output
A
AB
ABC
ABCD
ABCDE
1

Complete C Program

Fixed five rows: outer loop for the row, inner loop for the letters on that row, then reset ch to 'A' before the next row.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Character and counters

char ch = 'A'; holds the letter to print. i is the row index and j counts columns on that row.

Setup
2

Outer loop (rows)

for (i = 1; i <= 5; ++i) runs once per row. Row i will print exactly i letters.

Row control
3

Inner loop (letters)

for (j = 1; j <= i; ++j) with printf("%c", ch++) prints the current letter and advances ch to the next ASCII character.

Print & increment
4

New line and reset

After the inner loop, printf("\n") ends the row. Then ch = 'A' restores the starting letter so the next row again begins at A.

Start each row at A
=

Right-angled letter triangle

Total characters printed: 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.

2

Variation — User Input Version

Read the number of rows at runtime with scanf():

c
#include <stdio.h>

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

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Let the user choose row count with scanf()
  • Print each row in reverse (e.g. EDCBA on the last row)
  • Start from 'a' for lowercase output
  • Remove ch = 'A' to get a continuous alphabet down the triangle
  • Add spaces between letters for readability

Avoid

  • Forgetting to reset ch when you want each row to start at A
  • Using %d for letters—use %c for single characters
  • Skipping printf("\n") after each row
  • Ignoring invalid or negative input when using scanf()

Key Takeaways

1

Row i prints i letters, each row starting at 'A' when you assign ch = 'A' after every row.

2

ch++ in printf both prints the current character and moves to the next letter in ASCII order.

3

Complexity is O(n²) for n rows because the inner loop work grows with the row index.

4

The same nested-loop idea applies to star patterns and number patterns—only the printed symbol changes.

❓ Frequently Asked Questions

A variable ch starts at 'A'. The inner loop uses printf("%c", ch++) to print and advance. After each row you set ch = 'A' again so the next row begins at A.
Without resetting, ch would keep increasing across rows (e.g. A, then BC, then DEF). Resetting gives the classic pattern A, AB, ABC, ABCD, ABCDE.
Yes. Change the inner loop and the expression you print (for example count down and use 'A' + offset) so each row shows letters in the order you want.
O(n²) for n rows: the number of printed characters is 1+2+…+n = n(n+1)/2.

Explore More C Alphabet Patterns!

Dozens of letter-based triangles and pyramids build on the same loop ideas you used here.

All Alphabet Patterns →
Did you know?

In C, char is an integer type: 'A' + 1 is 'B'. That is why ch++ walks through the alphabet as long as you stay within the range you expect.

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