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 spaces between letters on each row).

This differs from program 1 style triangles where the inner loop uses 'A' + j per column; 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 codes 6569 ('A''E') to control row width. The actual letters come from k, incremented in printf.

c
#include <stdio.h>

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

    for (i = 65; i <= 69; ++i) {
        for (j = 65; j <= i; ++j) {
            printf("%c ", k++);
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

k = 65 ('A')

This is the running letter stream. It keeps increasing across the whole program, so the second row continues from where the first row left off instead of restarting at A.

Counter
2

Outer i as ASCII bound

i walks 6569 (AE). The inner loop j from 65 to i only decides how many cells belong to this row; the actual symbols always come from k.

Row width
3

printf("%c ", k++)

Each cell prints the current k as a character, prints a space, then post-increments k. That stitches one continuous sequence A, B, C, … across the triangle.

Sequence
4

printf("\n") between rows

When the inner loop finishes, you have printed exactly i - 64 letters on that row (for this i range). The newline moves to the next row while k stays ready for the next value.

New row
=

Continuous flood-fill

Fifteen letters for five rows is still n(n+1)/2. Nested loops over row length give O(n²) character output for n rows (plus spaces).

2

Variation — User Input + Character Literals

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

c
#include <stdio.h>

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

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    for (i = 'A'; i <= 'A' + rows - 1; ++i) {
        for (j = 'A'; j <= i; ++j) {
            printf("%c ", k++);
        }
        printf("\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
  • Use printf("%c", k++) to drop spaces between letters
  • 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++ (or k++ in printf) 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.
printf uses the value of k first, then k advances for the next character.
Run the outer loop while i <= 'A' + rows - 1 (with i as char or int), inner j from 'A' to i, same k++ body.
O(n²) for n rows.

Explore More C Alphabet Patterns!

One running counter is a simple way to stream letters through any row layout.

All Alphabet Patterns →
Did you know?

You can write the fixed five-row version with char k = 'A' and for (i = 'A'; i <= 'E'; ++i) — identical behavior to the 6569 version.

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