C++ Alphabet Pattern Programs

Beginner
6 min read
Updated: Nov 2026
3 examples
char + cout

Definition and Usage

A C++ alphabet pattern is a console program that prints letters in rows. The outer for loop chooses the row. The inner for loop prints each char with cout << letter, then cout << '\n' ends that row.

A char is an integer type, so letter++ walks A, B, C… Adding an int promotes the sum: 'A' + col is an int, and cout prints those digits (65, 66, 67). Cast with static_cast<char>('A' + col) when the shape should stay in A–Z.

Stream a char, not the sum.

cout << letter prints the character. cout << ('A' + col) prints the integer code unless you cast back to char first.

C++ Syntax

The same three pieces show up in every program below: a char loop, cout, and a newline after the inner loop.

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

for (char end = 'A'; end <= 'E'; end++) {
    for (char letter = 'A'; letter <= end; letter++)
        cout << letter;   // same line
    cout << '\n';        // end the row
}

How C++ Prints a Letter

Map each part of the console shape to a C++ type or stream insertion.

PieceC++What it does
Letterchar letter = 'A';Integer type that cout prints as a character
Next letterletter++A becomes B on the same row
Jumpstatic_cast<char>('A' + col)'A' + col is an int; the cast makes it a letter again
Same linecout << letterNo newline between letters
New rowcout << '\n'Finish the row
Flushcout << endlAlso ends the row, and flushes the stream
Indentcout << ' 'Leading spaces for pyramids
A–Z sliceletters.substr(0, n)Same growing row from a std::string

C++ Examples

Three programs. Each one changes only the C++ that picks the letter or the space.

Example 1 — Grow a row with a char loop

The outer char is the last letter on the row. The inner loop restarts at 'A'.

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

int main() {
    for (char end = 'A'; end <= 'E'; end++) {
        for (char letter = 'A'; letter <= end; letter++)
            cout << letter;
        cout << '\n';
    }
    return 0;
}

How It Works

  1. end runs from 'A' to 'E', one row per letter.
  2. The inner loop prints 'A' through end, so the row is A…end.
  3. cout << letter stays on the line; cout << '\n' starts the next row.

Example 2 — Cast the sum back to char

Skip the running char. Compute the letter from the column index.

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

int main() {
    int rows = 4;

    for (int row = 0; row < rows; row++) {
        for (int col = 0; col <= row; col++)
            cout << static_cast<char>('A' + col);
        cout << '\n';
    }
    return 0;
}

How It Works

  1. 'A' + col promotes to int.
  2. static_cast<char> turns that sum back into a letter before cout sees it.
  3. Without the cast, the same line prints 65, 6566, and so on.

Example 3 — Indent with cout << ' '

Print spaces before the letters so the triangle sits on the right.

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

int main() {
    int rows = 4;

    for (int row = 1; row <= rows; row++) {
        for (int space = 1; space <= rows - row; space++)
            cout << ' ';

        for (int col = 0; col < row; col++)
            cout << static_cast<char>('A' + col);

        cout << '\n';
    }
    return 0;
}

How It Works

  1. The first inner loop prints rows - row space characters.
  2. The second loop prints letters with the same static_cast<char>.
  3. Fewer spaces and more letters on each later row pull the shape right.

34 C++ Alphabet Pattern Programs

Each card is a full C++ program: nested for loops, char math, and the letters cout prints. Open one for the walkthrough.

Alphabet Pattern 1
Alphabet Pattern 2
Alphabet Pattern 3
Alphabet Pattern 4
Alphabet Pattern 5
Alphabet Pattern 6
Alphabet Pattern 7
Alphabet Pattern 8
Alphabet Pattern 9
Alphabet Pattern 10
Alphabet Pattern 11
Alphabet Pattern 12
Alphabet Pattern 13
Alphabet Pattern 14
Alphabet Pattern 15
Alphabet Pattern 16
Alphabet Pattern 17
Alphabet Pattern 18
Alphabet Pattern 19
Alphabet Pattern 20
Alphabet Pattern 21
Alphabet Pattern 22
Alphabet Pattern 23
Alphabet Pattern 24
Alphabet Pattern 25
Alphabet Pattern 26
Alphabet Pattern 27
Alphabet Pattern 28
Alphabet Pattern 29
Alphabet Pattern 30
Alphabet Pattern 31
Alphabet Pattern 32
Alphabet Pattern 33
Alphabet Pattern 34

Frequently Asked Questions

In C++, 'A' + col is an int. The usual arithmetic conversions promote the char before the addition, so the sum is 65, 66, 67… and operator<< for int prints those digits. Store the sum in a char, or use static_cast<char>('A' + col), and cout prints the letter.
cout << letter streams the char and stays on the same line, which is how each letter in a row is placed. cout << '\n' ends the row. Call it once after the inner loop. cout << endl also ends the row and flushes the stream; '\n' is enough for these programs.
Char math continues past 'Z' into other characters. For A–Z demos, keep rows between 1 and 26. After cin >> rows, check failure with if (!(cin >> rows)) before you use the value.
Yes. Store "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and call substr(0, length) for a row that always starts at A. Nested char loops are the skill these programs teach; substr is a shortcut once the shape is clear.

Next: Alphabet Pattern 1

A full C++ walkthrough of the right-angled letter triangle, from 'A' through cout << '\n'.

Alphabet Pattern 1 →

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.

28 people found this page helpful