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' in the five-row example, so widths go 5, 4, 3, 2, 1.
Contrast program 5 (same widths, but every row restarts at A) and program 3 (outer loop counts down, different first-row shape).
⭐ Pattern Output
For five rows ending at 'E':
ABCDE
BCDE
CDE
DE
EComplete C++ Program
Outer i from 65 to 69; inner j from i to 69, printing (char) j. Here 65 is 'A' and 69 is 'E'.
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 65; i <= 69; i++) {
for (j = i; j <= 69; j++)
cout << (char) j;
cout << "\n";
}
return 0;
}🧠 How It Works
Headers and namespace
#include <iostream> and using namespace std; enable cout.
Outer loop: start code
for (i = 65; i <= 69; i++) picks the first letter on each row: A, B, C, D, E.
Inner loop: run to E
for (j = i; j <= 69; j++) prints forward through the alphabet until 'E'. Every row shares the same right edge.
Line length
When the row starts at code i, you print 69 - i + 1 letters: five down to one for i from 65 to 69.
Five rows, fifteen letters
Total = 5+4+3+2+1 = n(n+1)/2 for n = 5 — O(n²) in general.
Variation — User Input Version
Set endCode = 65 + rows - 1 so the first row runs A through the last letter and the final row is a single character:
#include <iostream>
using namespace std;
int main() {
int rows;
int i, j;
cout << "Enter the number of rows: ";
cin >> rows;
int endCode = 65 + rows - 1;
for (i = 65; i <= endCode; i++) {
for (j = i; j <= endCode; j++)
cout << (char) j;
cout << "\n";
}
return 0;
}💡 Tips for Enhancement
Try These
- Rewrite loops with
charvariables and'A'/'E'for readability - Try lowercase with
endCode = 97 + rows - 1andistarting at97 - For A, AB, ABC, … see program 1
- Validate
cinand boundrowsso letters stay in range
Avoid
- Hard-coding
69when you already computedendCodefromrows - Confusing this with program 3 (same inner bound, opposite outer direction)
- Printing
jwithout(char)when usingintloop variables
Key Takeaways
Rising i moves the first letter right; j always runs up to the same end code.
Each row prints a contiguous forward slice of the alphabet.
General form: end = 65 + rows - 1, outer i from 65 to end, inner j from i to end.
Time complexity O(n²) for n rows.
❓ Frequently Asked Questions
i = 65, so j runs 65–69 → ABCDE. Next i = 66, so j runs 66–69 → BCDE, and so on.j <= 69, and 69 is 'E'. The last character printed on each row is always that letter (in the five-row fixed version).Explore More C++ Alphabet Patterns!
Small changes to outer-loop direction or inner bounds produce very different triangles.
The outer loop exits after i == 69; it does not run with i == 70. The condition is i <= 69, so the last row prints only E.
12 people found this page helpful
