Increasing Start Letter Alphabet Triangle in C

What You’ll Learn
Each row starts one letter later (A, B, C, …) but always runs through to 'E' on the first line’s alphabet range, so widths go 5, 4, 3, 2, 1.
Contrast program 5 (same widths, but every row restarts at A) and program 3 (different left/right edge rule).
⭐ Pattern Output
For five rows ending at 'E':
ABCDE
BCDE
CDE
DE
EComplete C Program (ASCII Values)
65 is 'A' and 69 is 'E' in ASCII. printf("%c", j) prints the character for code j.
#include <stdio.h>
int main() {
int i, j;
for (i = 65; i <= 69; ++i) {
for (j = i; j <= 69; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
}Same logic with character literals (often clearer): for (i = 'A'; i <= 'E'; ++i) and for (j = i; j <= 'E'; ++j).
🧠 How It Works
Outer loop: start code
i takes values 65–69 (A–E). That is the first letter printed on each row.
Inner loop: run to E
j runs from i up to 69, so every row ends at the same letter E.
Print as characters
printf("%c", j) outputs the letter for integer code j.
Line length
Row starting at code i prints 69 - i + 1 letters: five when i == 65, down to one when i == 69.
Five rows, fifteen letters
Total prints = 5+4+3+2+1 = 15 = n(n+1)/2 for n = 5 — O(n²) in general.
Variation — User Input Version
Set endChar = 'A' + rows - 1 so the last row is a single letter and the first row spells A through that letter.
#include <stdio.h>
int main() {
int rows, i, j;
int endChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
endChar = 'A' + rows - 1;
for (i = 'A'; i <= endChar; ++i) {
for (j = i; j <= endChar; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Prefer
'A'–'E'in loops instead of 65–69 unless you are demonstrating ASCII - Try lowercase:
endChar = 'a' + rows - 1 - For A, AB, ABC, … see program 1
- Check
scanfreturn value and sensible bounds onrows
Avoid
- Hard-coding
69when you already have a variableendChar - Assuming ASCII without noting your platform (fine for typical interview C)
- Using
%dif you want letters—use%c
Key Takeaways
Outer loop = starting letter; inner loop = sweep to a fixed last letter.
Integer codes and character literals are interchangeable in these loops.
Row count n still implies O(n²) total characters.
Pairs naturally with program 5 (same geometry, different restart rule).
❓ Frequently Asked Questions
i is the first code printed on the line. The inner j runs from i through 69 ('E'), so the first line is full A–E and each next line drops the leftmost letter.'A' and 'E' (or an endChar variable) in the loop bounds; the compiled code is the same idea.Explore More C Alphabet Patterns!
Switching between ASCII codes and character literals is a core C skill.
The rightmost column is always 'E' (or your endChar) because the inner loop always stops there—only the left bound moves.
12 people found this page helpful
