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

Incremental Alphabet Triangle (A, B C, C D E)

In the incremental alphabet triangle each row starts one letter later than the row above and then counts forward: A, B C, C D E, D E F G. The last letter of each row goes up two at a time: A, C, E, G, I.

Quick answer: Row i prints i letters starting at the i-th letter. So the letter at position j is 'A' + i + j − 2. The last letter of row i is the (2i − 1)-th letter of the alphabet.

This program is part of the String Patterns collection.

Table of contents8 sections
  1. Incremental Alphabet Triangle output
  2. How the incremental alphabet triangle works
  3. Incremental Alphabet Triangle in C
  4. Incremental Alphabet Triangle in C++
  5. Incremental Alphabet Triangle in Java
  6. Incremental Alphabet Triangle in Python
  7. Time and space complexity
  8. Frequently asked questions

Incremental Alphabet Triangle output

Output (n = 5):

A
B C
C D E
D E F G
E F G H I
Incremental Alphabet Triangle layout diagram, row by row (n = 5)
How each row of the incremental alphabet triangle is built (n = 5). Blue cells are printed characters; grey dots are spaces.

Same shape, other characters: the 0-1 (Binary) Triangle, Alphabet Triangle, Descending Alphabet Triangle, Hash (#) Right Triangle and Reverse Alphabet 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 incremental alphabet triangle works

Both counters move the letter forward: the row sets the start and the position walks along from there. That is why the start rises by one per row while the end rises by two. The number version of the same idea is the stepped number triangle (1, 23, 345).

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

Key takeaways

  • Each row starts at its own letter and counts forward.
  • The last letter is letter 2i − 1: A, C, E, G, I.
  • Letters repeat down the diagonals from top left to bottom right.
  • Thirteen rows would end at Y; fourteen would run past Z.

Incremental Alphabet Triangle in C

#include <stdio.h>

int main(void) {
    int n = 5;

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

Incremental Alphabet Triangle in C++

#include <iostream>
using namespace std;

int main() {
    int n = 5;

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

Incremental Alphabet Triangle in Java

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

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

Incremental Alphabet Triangle in Python

n = 5

for i in range(1, n + 1):
    for j in range(1, i + 1):
        print(chr(ord('A') + i + j - 1 - 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

What is the difference from the continuous alphabet triangle?

In a continuous triangle the letters never repeat: A, B C, D E F. Here each row restarts one letter after the previous start, so C appears on rows 2 and 3.

How do I right-align it?

Print n − i double spaces before each row; each letter plus its space takes two characters.

How do I let the user choose the number of rows?

Read n from the keyboard instead of fixing it in the code: scanf("%d", &n); in C, cin >> n; in C++, new Scanner(System.in).nextInt() in Java and int(input()) in Python.

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 16 of 22 in String 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.