Right-Angled Triangle Alphabet Pattern in C

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:
A
AB
ABC
ABCD
ABCDEComplete 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.
#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
Character and counters
char ch = 'A'; holds the letter to print. i is the row index and j counts columns on that row.
Outer loop (rows)
for (i = 1; i <= 5; ++i) runs once per row. Row i will print exactly i letters.
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.
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.
Right-angled letter triangle
Total characters printed: 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.
Variation — User Input Version
Read the number of rows at runtime with scanf():
#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
chwhen you want each row to start at A - Using
%dfor letters—use%cfor single characters - Skipping
printf("\n")after each row - Ignoring invalid or negative input when using
scanf()
Key Takeaways
Row i prints i letters, each row starting at 'A' when you assign ch = 'A' after every row.
ch++ in printf both prints the current character and moves to the next letter in ASCII order.
Complexity is O(n²) for n rows because the inner loop work grows with the row index.
The same nested-loop idea applies to star patterns and number patterns—only the printed symbol changes.
❓ Frequently Asked Questions
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.ch would keep increasing across rows (e.g. A, then BC, then DEF). Resetting gives the classic pattern A, AB, ABC, ABCD, ABCDE.'A' + offset) so each row shows letters in the order you want.Explore More C Alphabet Patterns!
Dozens of letter-based triangles and pyramids build on the same loop ideas you used here.
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.
12 people found this page helpful
