Sequential Alphabet Triangle in C#

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).
This differs from program 1 style triangles where letters reset per row; here one counter walks the alphabet continuously.
⭐ Pattern Output
For 5 rows (space between letters):
A
B C
D E F
G H I J
K L M N OComplete C# Program
Use a single running character k starting at 'A'. Increment it after every print so letters stay consecutive across the whole triangle.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
char k = 'A';
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(k);
if (j < i) Console.Write(" ");
k++;
}
Console.WriteLine();
}
}
}
}🧠 How It Works
One running character
k starts at 'A' and never resets between rows.
Outer loop sets row width
Row i prints i characters: 1, 2, 3, 4, 5.
Increment per character
The statement k++ runs inside the inner loop, so each printed cell advances to the next letter.
Total letters printed
For 5 rows, you print 1+2+3+4+5 = 15 letters. In general it is \(n(n+1)/2\), so complexity is O(n²).
Variation — User Input Version
Read rows and keep printing until you finish. If you want to stay in A–Z only, cap rows (or stop when k passes 'Z').
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number of rows: ");
int rows = Convert.ToInt32(Console.ReadLine());
char k = 'A';
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(k);
if (j < i) Console.Write(" ");
k++;
}
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Remove spaces if you prefer a compact look
- Use lowercase by starting
k = 'a' - Compare with Program 1 (letters reset each row)
- Stop when
kreaches'Z'if you want only A–Z
Avoid
- Incrementing
konly once per row (that would repeat the same letter on the row) - Assuming the alphabet wraps automatically after
'Z'(it doesn’t) - Printing
iinstead ofkif you want sequential letters
Key Takeaways
Use one running character that never resets.
Increment inside the inner loop to advance per cell.
Row width is controlled by the outer loop (1..n).
Complexity is O(n²) for n rows.
❓ Frequently Asked Questions
k is updated after every printed character and is not reset inside the outer loop.Explore More C# Alphabet Patterns!
Continuous counters like k are useful anytime you want values to flow across rows.
If you remove the spaces, the triangle becomes more compact, but the same k++ logic still produces consecutive letters.
12 people found this page helpful
