Decreasing & Increasing Alphabet Rows in C

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

What You’ll Learn

Each line is descending from the row letter down to B, then ascending from A to a cap chosen so the line always has five characters (for AE). The cap is 'A' + 'E' - i, which matches 134 - i in ASCII.

Near kin: program 24 (palindrome triangle) uses a similar split around A.

⭐ Pattern Output

Adjacent %c, no spaces:

Output
ABCDE
BABCD
CBABC
DCBAB
EDCBA
1

ASCII version (134 - i)

Same as k <= 65 + 69 - i for row index i.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Outer i is the row anchor (ASCII)

i runs 6569 (AE). It defines the leftmost “high” letter on the row; the second loop fills the ascending tail that balances the line to fixed length.

A→E
2

Descending leg: j from i toward B

Using ASCII, for (j = i; j > 65; --j) prints i, then i-1, down to B. When i == 'A' the condition fails immediately, so the first row has no descending prefix.

i↓B
3

Ascending leg: k up to 134 - i

The second loop walks k from 65 through 134 - i, which equals 65 + 69 - i ('A' + 'E' - i in ASCII). As i increases, the cap drops so the row stays five letters wide.

Cap
4

Constant row length

Descending count is i - 65 letters; ascending count is (134 - i) - 65 + 1 = 69 - i + 1 letters. Their sum is 69 - 65 + 1 = 5 for every row in this range.

5
=

Bow-tie pattern

Middle rows splice a descending prefix with an ascending tail, so they read almost palindromic. First and last rows are one-sided ramps. Two inner passes per row → O(n²) for n letters.

2

Character literals & user input

Use 'A' + endChar - i (not 2 * endChar - i) so the bound stays correct when i == 'A'.

c
#include <stdio.h>

int main() {
    int rows;
    int i, j, k;
    char startChar, endChar;

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

    startChar = 'A';
    endChar = (char)('A' + rows - 1);

    for (i = startChar; i <= endChar; ++i) {
        for (j = i; j > startChar; --j) {
            printf("%c", j);
        }
        for (k = startChar; k <= (startChar + endChar - i); ++k) {
            printf("%c", k);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Print spaces between letters for readability
  • Generalize startChar and endChar from input with validation
  • Derive the cap as endChar - (i - startChar) after rewriting the sum

Avoid

  • 2 * endChar - i as the upper limit when startChar is 'A' (wrong for the first row)
  • Using j >= 'A' in the first loop without removing A from the second

Key Takeaways

1

Upper bound for k: startChar + endChar - i (ASCII 134 - i for AE).

2

First loop only emits down to B so A is not doubled.

3

Every row length equals endChar - startChar + 1.

4

O(n²) for n rows over an n-letter span.

❓ Frequently Asked Questions

For i == 'A' and endChar == 'E', that expression overshoots past E. The correct symmetric cap is startChar + endChar - i.
65 + 69, i.e. 'A' + 'E', so 134 - i is just 'A' + 'E' - i written as integers.
Program 26 rotates a fixed width-5 window. Here each row stitches a descending prefix and an ascending suffix with a computed cap.
O(n²) character prints for n rows.

Explore More C Alphabet Patterns!

Encoding the ascending bound as start + end - row keeps row length stable without hard-coding magic numbers beyond your letter range.

All Alphabet Patterns →
Did you know?

Letters printed in the second loop count (A + E - i) - A + 1 = E - i + 1; together with i - A letters from the first loop you always get E - A + 1 per row.

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