Increasing Start Letter Alphabet Triangle in C++

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

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':

Output
ABCDE
BCDE
CDE
DE
E
1

Complete 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'.

C++
#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

1

Headers and namespace

#include <iostream> and using namespace std; enable cout.

Setup
2

Outer loop: start code

for (i = 65; i <= 69; i++) picks the first letter on each row: A, B, C, D, E.

Start moves right
3

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.

Fixed end
4

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.

Shrinking width
=

Five rows, fifteen letters

Total = 5+4+3+2+1 = n(n+1)/2 for n = 5 — O(n²) in general.

2

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:

C++
#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 char variables and 'A' / 'E' for readability
  • Try lowercase with endCode = 97 + rows - 1 and i starting at 97
  • For A, AB, ABC, … see program 1
  • Validate cin and bound rows so letters stay in range

Avoid

  • Hard-coding 69 when you already computed endCode from rows
  • Confusing this with program 3 (same inner bound, opposite outer direction)
  • Printing j without (char) when using int loop variables

Key Takeaways

1

Rising i moves the first letter right; j always runs up to the same end code.

2

Each row prints a contiguous forward slice of the alphabet.

3

General form: end = 65 + rows - 1, outer i from 65 to end, inner j from i to end.

4

Time complexity O(n²) for n rows.

❓ Frequently Asked Questions

First outer iteration has i = 65, so j runs 65–69 → ABCDE. Next i = 66, so j runs 66–69 → BCDE, and so on.
The inner condition is j <= 69, and 69 is 'E'. The last character printed on each row is always that letter (in the five-row fixed version).
Program 5 always starts each row at A and shortens toward E. Program 6 shifts the start forward each row while still ending at E.
O(n²) for n rows: n(n+1)/2 characters.

Explore More C++ Alphabet Patterns!

Small changes to outer-loop direction or inner bounds produce very different triangles.

All Alphabet Patterns →
Did you know?

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.

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