Triangle with Reverse Starting Letter in C

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':
E
DE
CDE
BCDE
ABCDEComplete 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.
#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
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').
First letter of the row
currentChar = startChar - i. When i is 0, 1, 2, … the row starts at E, D, C, …
Print forward along the row
j from 0 to i: print currentChar + j. That is i + 1 letters on row i.
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.
Reverse start, forward run
Work grows like 1+2+…+n, so time complexity is O(n²).
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.
#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
iwith 1-based row counts when reasoning aboutstartChar - i - Letting
nso large thatstartChar - igoes before'A'unless that is intentional - Using
%dinstead of%cfor letters
Key Takeaways
currentChar = startChar - i moves the starting letter left along the alphabet each row.
printf("%c", currentChar + j) walks forward inside the row.
Algebra: last letter on row i is always startChar, so the right column is straight.
Same O(n²) cost as other triangle letter patterns.
❓ Frequently Asked Questions
currentChar = startChar - i with row index i starting at 0. The inner loop prints currentChar + j for j = 0 through i.(startChar - i) + i = startChar. So with startChar == 'E', each row’s last letter is E.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.Explore More C Alphabet Patterns!
Character arithmetic plus nested loops unlock many interview-style shapes.
The identity (startChar - i) + j with j = i always equals startChar, which is why the right side of the triangle lines up vertically.
12 people found this page helpful
