C sharp Programs on Alphabetic Patterns- Learn how to print alphabet or Character patterns of different forms.
Alphabet value of ‘A’ is 65.
Alphabet value of ‘a’ is 97.
Input Format
The input will contain single integer value.
Input Value
5
Output Format-1
A
AB
ABC
ABCD
ABCDE
C# Example Program to print Output Format-1 Pattern
class Program
{
static void Main(string[] args)
{
// input value to print number of lines
int n = 5;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0}", (char)(j + 64));
}
Console.Write("\n");
}
}
}
Output Format-2
E
DE
CDE
BCDE
ABCDE
C# Example Program to print Output Format-2 Pattern
class Program
{
static void Main(string[] args)
{
//input value to print number of lines
int n = 5;
for (int i = n; i >= 1; i--)
{
for (int j = i; j <= n; j++)
{
Console.Write("{0}", (char)(j + 64));
}
Console.Write("\n");
}
}
}