New: 213 pattern programs with tested code in C, C++, Java and Python Explore patterns

Continuous Alphabet Pyramid (A, B C, D E F)

The continuous alphabet pyramid keeps going through the alphabet instead of starting again on each row: A, then B C, then D E F. Five rows use the letters A to O.

Quick answer: Row i starts right after the i(i − 1)/2 letters used by the rows above, so the letter at position j is 'A' + i(i − 1)/2 + j − 1. Centre each row with n − i spaces and print each letter with a space after it.

This program is part of the Pyramid Patterns collection.

Table of contents8 sections
  1. Continuous Alphabet Pyramid output
  2. How the continuous alphabet pyramid works
  3. Continuous Alphabet Pyramid in C
  4. Continuous Alphabet Pyramid in C++
  5. Continuous Alphabet Pyramid in Java
  6. Continuous Alphabet Pyramid in Python
  7. Time and space complexity
  8. Frequently asked questions

Continuous Alphabet Pyramid output

Output (n = 5):

    A
   B C
  D E F
 G H I J
K L M N O
Continuous Alphabet Pyramid layout diagram, row by row (n = 5)
How each row of the continuous alphabet pyramid is built (n = 5). Blue cells are printed characters; grey dots are spaces.

Same shape, other characters: the Alphabet Pyramid Pattern, Centred Repeated Number Pyramid, Dollar ($) Pyramid, Number Pyramid Pattern and Pascal’s Triangle programs draw this same outline with different characters. Putting them side by side shows which part of the loop decides the shape and which part decides what is printed.

How the continuous alphabet pyramid works

The letters follow the same order as the numbers in Floyd’s triangle: 1, 2 3, 4 5 6. Converting each Floyd number k to the letter 'A' + k − 1 gives this pattern. The triangle-number formula i(i − 1)/2 says how many letters came before row i, so no counter is needed.

  1. Run the outer loop for i from 1 to n, one row per pass.
  2. Print n − i spaces.
  3. Print i letters (letter number i × (i − 1) / 2 + j).
  4. Move to the next line.

Key takeaways

  • The letters follow Floyd’s order: they never restart.
  • i(i − 1)/2 counts the letters used by earlier rows.
  • Six rows would need 21 letters and seven rows 28, so stop at six to stay within A to Z.
  • A running counter ch++ gives the same output.

Continuous Alphabet Pyramid in C

#include <stdio.h>

int main(void) {
    int n = 5;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - i; j++)
            printf(" ");
        for (int j = 1; j <= i; j++)
            printf("%c ", 'A' + i * (i - 1) / 2 + j - 1);
        printf("\n");
    }
    return 0;
}

Continuous Alphabet Pyramid in C++

#include <iostream>
using namespace std;

int main() {
    int n = 5;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - i; j++)
            cout << " ";
        for (int j = 1; j <= i; j++)
            cout << char('A' + i * (i - 1) / 2 + j - 1) << " ";
        cout << endl;
    }
    return 0;
}

Continuous Alphabet Pyramid in Java

public class ContinuousAlphabetPyramid {
    public static void main(String[] args) {
        int n = 5;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i; j++)
                System.out.print(" ");
            for (int j = 1; j <= i; j++)
                System.out.print((char) ('A' + i * (i - 1) / 2 + j - 1) + " ");
            System.out.println();
        }
    }
}

Continuous Alphabet Pyramid in Python

n = 5

for i in range(1, n + 1):
    for j in range(1, n - i + 1):
        print(" ", end="")
    for j in range(1, i + 1):
        print(chr(ord('A') + i * (i - 1) // 2 + j - 1), end=" ")
    print()

Time and space complexity

The program prints one character for each position in the pattern, so for n rows it runs in O(n²) time. It only needs a few loop variables, so the extra memory is O(1).

Frequently asked questions

How many rows fit in the alphabet?

Six rows use 21 letters (A to U). Seven rows would need 28, two more than the alphabet has, so keep n at 6 or less, or wrap around with % 26.

Can I use a counter instead of the formula?

Yes. Set ch = 'A' before the loops and print ch++ in the inner loop. It is shorter; the formula is handy when you need a single row.

How is it different from the alphabet pyramid?

The alphabet pyramid starts every row at A. This one carries on through the alphabet from row to row.

This tutorial was drafted with AI assistance. Spotted a mistake? Tell us and we fix it. Read our editorial policy.

Quick check: can you predict the output?

Answer from the code, then check. Every answer comes from the real output above.

Pattern 15 of 19 in Pyramid Patterns

 

Still stuck? Ask AI to explain this code

Opens your favourite AI with this page, ready to explain every loop step by step.

Authored by

Ghanendra Yadav runs Pattern Programs from Bangalore, India. The site started in 2020 to help students practise loops and logic through pattern programs in C, C++, Java and Python. Every program published here is compiled and run before it goes live, and the output shown is the real output.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.