C# Pola Spiral Alphabet

Spiral Alphabet | C# Spiral Pattern
Spiral Alphabet | C# Spiral Pattern

C# Spiral Alphabet adalah pola suatu huruf jalan terus menerus yang berasal dari titik pusat, berputar mengelilinginya dan bertambah jauh darinya pada C#, Biasanya pola spiral alphabet ini sering ditemukan sebagai tugas kuliah bagi para Dosen, ataupun guru di Indonesia, Untuk melatih logika, Kamu harus mencoba berbagai macam pola program pada C#

Berikut Source Code pola spiral alphabet atau pattern spiral alphabet.

int n = 8;
int[,] a = new int[8, 8];
int i, j;
int ot;

int x = 0, y = 0, z = 0;

for (ot = 0; ot <= n / 2; ot++)
{
    if (ot == n / 2)
    {
        z--;
    }
    for (j = y; j < n - y; j++)
    {
        a[x, j] = z;
        z++;
    }
    for (i = x + 1; i < n - x - 1; i++)
    {
        a[i, n - y - 1] = z;
        z++;
    }
    for (j = n - y - 1; j >= y; j--)
    {
        a[n - x - 1, j] = z;
        z++;
    }
    for (i = n - x - 2; i > x; i--)
    {
        a[i, y] = z;
        z++;
    }
    x++;
    z++;
}
for (i = 0; i < n; i++)
{
    for (j = 0; j < n; j++)
    {
        if (a[i, j] >= 26)
        {
            a[i, j] %= 26;
        }
        Console.Write(" " + (char)(a[i, j] + 65) + " ");
    }
    Console.WriteLine();
}
Console.ReadKey(true);

Output :

 A  B  C  D  E  F  G  H
 D  E  F  G  H  I  J  K
 C  D  E  F  G  H  I  J
 C  B  A  Z  Y  X  W  V
 N  O  P  Q  R  S  T  U
 T  S  R  Q  P  O  N  M
 W  V  U  T  S  R  Q  P
 V  U  T  S  R  Q  P  O

Leave a Reply

Your email address will not be published. Required fields are marked *