C# Alphabet Pattern (Decrease then Increase)

Beginner
7 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

Decreasing and increasing alphabet rows keep a fixed width: each row starts with a growing descending prefix, then fills the rest with a shrinking ascending suffix from A.

Remember
Rule: prefix i..1  +  suffix 0..(n−i)   →  width = n+1

ABCDE
BABCD
CBABC
DCBAB
EDCBA     ← end = 'E' (n = 4)

As the left side grows (B, CB, DCB, …), the right side shrinks (ABCD, ABC, AB, A) so every line stays the same length. Compare with Program 24 (palindrome triangles) and Program 29 (layered diamond).

How to Solve It

Two ways to emit the same grid — inline two loops per row, or factor a PrintRow helper.

MethodIdeaBest for
Two loops inlineDescending i..1, then ascending 0..(n−i)Learning, interviews, exams
PrintRow helperOne method owns both parts; outer loop only picks iCleaner demos once the width budget clicks

Pseudocode

Pseudocode
n = end - 'A'
for i from 0 to n:
    for j from i down to 1:   print alpha[j]
    for k from 0 to n - i:    print alpha[k]
    print newline

Cheat sheet

GoalPattern
End indexint n = end - 'A'; (4 for E)
Rowsfor (int i = 0; i <= n; i++)
Descending prefixfor (int j = i; j > 0; j--) Write(alpha[j]);
Ascending suffixfor (int k = 0; k <= n - i; k++) Write(alpha[k]);
Skip duplicate APrefix stops at j > 0 (never prints index 0)
WidthAlways n + 1 (i + (n − i + 1))
Palindrome trianglesSee Program 24

Write vs WriteLine

APIEffectUse for
Console.WriteStays on the same lineEach letter in both parts
Console.WriteLineEnds the current lineAfter both loops finish a row

Live Preview

Change the end letter and the fixed-width decreasing/increasing grid updates instantly — every row has length n + 1.

One letter from A to F. Tap a chip or type a letter — the preview redraws as you go.

Live result End E · 5 rows · width 5
ABCDE
BABCD
CBABC
DCBAB
EDCBA

Worked Walkthrough — End = E (n = 4)

Trace each row index, both parts, and the joined 5-letter line.

iPrefix (i..1)Suffix (0..4−i)Printed row
0(empty)ABCDEABCDE
1BABCDBABCD
2CBABCCBABC
3DCBABDCBAB
4EDCBAEDCBA

Width is always 4 + 1 = 5. The last row is a full reverse run ending at a single A.

C# Programs

Three complete programs: fixed A–E, end-letter input, and a helper-method rewrite. Use View Output to reveal sample results.

Example 1 — Fixed A–E

Matches the reference logic: print alpha[i]…alpha[1], then alpha[0]…alpha[4 − i].

C#
using System;

class Program
{
    static void Main()
    {
        char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

        for (int i = 0; i <= 4; i++)
        {
            for (int j = i; j > 0; j--)
                Console.Write(alpha[j]);

            for (int k = 0; k <= 4 - i; k++)
                Console.Write(alpha[k]);

            Console.WriteLine();
        }
    }
}

How It Works

1. Row index sets the start. Outer loop runs i from 0 to 4 (letters A…E).

2. Descending prefix (skip A). j runs from i down to 1 — when i = 2, that prints CB.

3. Ascending suffix fills the rest. k runs from 0 to 4 − i — when i = 2, that prints ABC.

4. Constant width. Prefix length + suffix length is always 5 (CBABC).

Example 2 — End Letter Input

Works for A..end with the same two-part row. Prefer validating a single A–Z character in real apps.

C#
using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter end letter (like E): ");
        char end = Convert.ToChar(Console.ReadLine());

        int n = end - 'A';
        char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

        for (int i = 0; i <= n; i++)
        {
            for (int j = i; j > 0; j--)
                Console.Write(alpha[j]);

            for (int k = 0; k <= n - i; k++)
                Console.Write(alpha[k]);

            Console.WriteLine();
        }
    }
}

How It Works

1. Scale with n. n = end - 'A' drives both loops. For end = C, width is 3 and you get three rows.

2. Same core. Only the end index changes; the prefix/suffix width budget is unchanged.

3. Safer input tip. Prefer:

Safer input
string raw = (Console.ReadLine() ?? "").Trim().ToUpperInvariant();
if (raw.Length != 1 || raw[0] < 'A' || raw[0] > 'Z')
{
    Console.WriteLine("Enter one letter from A to Z.");
    return;
}
char end = raw[0];

Example 3 — Helper Method

Often clearer: one method owns both parts so Main only walks row indexes.

C#
using System;

class Program
{
    static void PrintRow(char[] alpha, int n, int i)
    {
        for (int j = i; j > 0; j--)
            Console.Write(alpha[j]);

        for (int k = 0; k <= n - i; k++)
            Console.Write(alpha[k]);

        Console.WriteLine();
    }

    static void Main()
    {
        int n = 4;
        char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

        for (int i = 0; i <= n; i++)
            PrintRow(alpha, n, i);
    }
}

How It Works

1. PrintRow owns both parts. Prefix and suffix live in one place.

2. Thin outer loop. Main only decides which row index i to print.

Edge Cases & Pitfalls

Check these before calling the solution done.

j >= 0

Duplicate A at the join

If the prefix includes index 0, you get …AA…. Keep for (j = i; j > 0; j--).

Wrong suffix end

Uneven row widths

Suffix must stop at n − i. Ending at a fixed n makes later rows too long.

WriteLine inside

Column of letters

If WriteLine is inside either loop, each letter lands on its own line. Use Write for letters; WriteLine only after both parts.

end = A

Single A

When n = 0, you print one row: A. A good sanity check.

i = 0

Empty prefix is normal

The first row prints only the ascending suffix A..end — that is expected, not a bug.

Bad input

Validate one letter

Trim, uppercase, and require length 1 in A–Z — reject empty or multi-character lines.

Time and Space Complexity

ProgramTimeExtra space
Two loops inline (Examples 1–2)O(n²)O(1) (plus the fixed alphabet table)
Helper method (Example 3)O(n²)O(1)

For letters A..end there are n + 1 rows, each of width n + 1 — quadratic in n.

Key Takeaways

  • Rule: prefix i..1 + suffix 0..(n − i).
  • Width budget: prefix grows as suffix shrinks — total always n + 1.
  • Break the row: call WriteLine only after both loops.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each i, print i down to B, then A up through index n − i.

Frequently Asked Questions

A is printed in the second loop. If the first loop included A, the join would duplicate A.
To keep each row the same width, end the ascending part at indices 0..(n − i). For A..E that is A + E − i, so both parts always add up to n+1 letters.
Yes. Set n = end − 'A' and keep the same loops: descending j from i down to 1, then ascending k from 0 to n − i.
O(n²) for n letters because there are n rows and each row prints O(n) characters.
The descending prefix has length i and the ascending suffix has length (n − i + 1). Together they always equal n + 1.
Read a line, trim it, require a single A–Z character (or ToUpperInvariant), and reject empty or multi-character input.
Program 24 builds palindrome triangles around A. This page keeps fixed-width rows by trading a growing descending prefix against a shrinking ascending suffix.
The descending loop does nothing, so you print only the ascending suffix A..end — for E that is ABCDE.

Did you know?

For each row i (A..E), print a descending prefix from i down to B (skip A), then print an ascending suffix from A up to A + E - i. That cap keeps row width constant at E - A + 1.

Next: V-Shaped Alphabet Pattern

Move from fixed-width letter rows to a V drawn only on two diagonals meeting at the tip.

Program 31 tutorial →

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