Sequential Alphabet Triangle in C++

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

What You’ll Learn

Each row is wider than the last, but letters stay in order across the whole shape: A, then B C, then D E F, up to K L M N O for five rows (with a space after each letter).

This differs from program 1 style triangles where each column is derived from j; here one counter k walks the alphabet continuously.

⭐ Pattern Output

For 5 rows (space after each letter):

Output
A
B C
D E F
G H I J
K L M N O
1

Complete C++ Program (Five Rows, ASCII Loops)

Loop variables i and j use ASCII 6569 to control row width. The actual letters come from k, post-incremented in each cout.

C++
#include <iostream>
using namespace std;

int main() {
    int i, j;
    int k = 65;

    for (i = 65; i <= 69; i++) {
        for (j = 65; j <= i; j++)
            cout << (char) k++ << " ";
        cout << "\n";
    }
    return 0;
}

🧠 How It Works

1

k = 65 ('A')

Global position in the alphabet; it never resets between rows.

Counter
2

Outer i

Each value of i sets how many inner iterations run (1, 2, 3, 4, 5).

Row width
3

cout << (char) k++ << " "

Print the current letter, append a space, then advance k for the next cell.

Sequence
4

cout << "\n"

After the inner loop finishes one row, start the next line.

New row
=

Fifteen letters for five rows

O(n²) letters for n rows.

2

Variation — User Input + Character Literals

Same idea with readable 'A' bounds; last row ends at 'A' + rows - 1.

C++
#include <iostream>
using namespace std;

int main() {
    int rows;
    int i, j;
    char k = 'A';

    cout << "Enter the number of rows: ";
    cin >> rows;

    for (i = 'A'; i <= 'A' + rows - 1; i++) {
        for (j = 'A'; j <= i; j++)
            cout << k++ << " ";
        cout << "\n";
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Fixed five rows with char k and for (i = 'A'; i <= 'E'; i++) — same output, clearer than 65
  • Omit the space in cout if you want a tight triangle
  • Cap rows so k does not pass 'Z'

Avoid

  • Resetting k to 'A' at every row (you would repeat A, BB, … instead of a run-through)
  • Incrementing k only once per row (not enough letters on wider rows)

Key Takeaways

1

Inner loop count matches row width; k carries the alphabet forward.

2

k++ in the output runs once per printed character.

3

O(n²) output size for n rows.

4

ASCII and character-literal loops are interchangeable here.

❓ Frequently Asked Questions

It only repeats the body the right number of times for that row. The value printed is always the current k.
cout uses the value of k first, then k advances for the next character.
Run the outer loop while i <= 'A' + rows - 1, inner j from 'A' to i, same k++ body.
O(n²) for n rows.

Explore More C++ Alphabet Patterns!

One global k is the trick: row loops only decide how many times to print, not which letter.

All Alphabet Patterns →
Did you know?

This is the same structure as the C tutorial: printf("%c ", k++) and cout << (char) k++ << " " both advance the alphabet once per cell.

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